Sample 47312: Create a user-defined format containing decile ranges from PROC UNIVARIATE results
The sample program on the
Full Code tab uses a PROC UNIVARIATE step to create an output data set containing decile values for an analysis variable. After transposing the output data set, DATA step processing is used to create a data set that can be used in the CNTLIN= option of PROC FORMAT. The user-defined format containing the decile ranges can then be used in a DATA step or procedure step.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
The sample program below uses a PROC UNIVARIATE step to create an output data set containing decile values for an analysis variable. After transposing the output data set, DATA step processing is used to create a data set that can be used in the CNTLIN= option of PROC FORMAT. The user-defined format containing the decile ranges can then be used in a DATA step or procedure step.
/* Create a sample data set */
data test;
do i=1 to 137;
xyz=int(ranuni(1)*1234);
output;
end;
drop i;
run;
proc sort data=test;
by xyz;
run;
/* Request deciles with the PCTLPTS= option */
proc univariate data=test noprint;
var xyz;
output out=out1 pctlpts=10 to 100 by 10 pctlpre=P;
run;
ods noproctitle;
proc print data=out1;
title 'PROC UNIVARIATE Results';
run;
proc transpose data=out1 out=out2 (rename=(col1=end));
run;
/* Create the CNTLIN data set */
data crfmt;
set out2 end=last;
if _N_=1 then hlo='L';
start=lag(end);
label='>' || catx(' - ',start,end);
if hlo='L' then label=catx(' - ','low',end);
fmtname='xfmt';
eexcl='N';
if last then do;
hlo='H';
label='>' || catx('- ',start,'high');
end;
run;
proc print data=crfmt;
var fmtname start end label eexcl hlo;
title 'CNTLIN data set';
run;
/* Create a format based on deciles */
proc format cntlin=crfmt;
select xfmt;
run;
/* Use the format in a procedure step */
proc freq data=test;
tables xyz;
format xyz xfmt.;
title 'Decile Counts';
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Use a combination of PROC UNIVARIATE, PROC TRANSPOSE, DATA step, and PROC FORMAT to create a user-defined format containing decile ranges.
Date Modified: | 2012-09-05 13:58:30 |
Date Created: | 2012-08-24 13:48:46 |
Operating System and Release Information
SAS System | Base SAS | Tru64 UNIX | 9.1 TS1M0 | |
OpenVMS Alpha | 9.1 TS1M0 | |
Linux | 9.1 TS1M0 | |
HP-UX IPF | 9.1 TS1M0 | |
64-bit Enabled Solaris | 9.1 TS1M0 | |
64-bit Enabled HP-UX | 9.1 TS1M0 | |
64-bit Enabled AIX | 9.1 TS1M0 | |
Microsoft Windows XP Professional | 9.1 TS1M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M0 | |
Microsoft Windows NT Workstation | 9.1 TS1M0 | |
Microsoft Windows 2000 Professional | 9.1 TS1M0 | |
Microsoft Windows 2000 Server | 9.1 TS1M0 | |
Microsoft Windows 2000 Datacenter Server | 9.1 TS1M0 | |
Microsoft Windows 2000 Advanced Server | 9.1 TS1M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M0 | |
z/OS | 9.1 TS1M0 | |