Help using Base SAS procedures

PROC UNIVARIATE PERCENTILES BY VARIABLE IN OUTPUT DATASET

Reply
N/A
Posts: 0

PROC UNIVARIATE PERCENTILES BY VARIABLE IN OUTPUT DATASET

OK, The basic idea is to run PROC UNI like this

PROC UNIVARIATE DATA=WORK.RECV_GL_CLEAN;
VAR A;
OUTPUT OUT=WORK.QUANTILES PCTLPRE=P_ PCTLPTS=0 to 100 by 5;
RUN;

I know I can put another var on the VAR line, but I get 20 additional columns for each variable I have.

I need to do this on 500+ variables [long story]

What I really want is an output data set like this:

VAR_NAME P_0 P_5 ... P_100
...
...

Where each observation is the variable name followed by the percentiles.

I tried an ODS solution but the QUANTILES object doesn't look at the PCTLPTS paramters it only holds the default one.

I also tried using PROC MEANS but I can't figure out how to specify PCTLPTS in PROC MEANS.

Any ideas?

Thanks,
Ike
SAS Super FREQ
Posts: 8,744

Re: PROC UNIVARIATE PERCENTILES BY VARIABLE IN OUTPUT DATASET

Hi:
You may have to look at a Macro program solution, then. The thing is that it looks like ODS OUTPUT does not collect the PCTLPTS info. And since you don't want PROC UNIVARIATE to put ALL your variables into one obs, you're going to have to make multiple passes through the data anyway.

I can get this output:
[pre]
after running macro program

Obs varname P_0 P_5 P_10 P_15 P_20 P_25 P_30 P_35 P_40 P_45 P_50 P_55 P_60 P_65 P_70 P_75 P_80 P_85 P_90 P_95 P_100

1 age 11.0 11.0 11.0 12.0 12.0 12.0 12.0 12.0 13.0 13.0 13.0 14.0 14.0 14.0 14.0 15.0 15.0 15 15 16 16
2 height 51.3 51.3 56.3 56.5 57.3 57.5 59.0 59.8 62.5 62.5 62.8 63.5 64.3 64.8 65.3 66.5 66.5 67 69 72 72
3 weight 50.5 50.5 77.0 83.0 84.0 84.0 84.5 85.0 90.0 98.0 99.5 102.5 102.5 112.0 112.0 112.5 112.5 128 133 150 150

[/pre]

...by running the macro program below.

You can automatically generate the macro calls (%dovars invocation) for each variable, if you know how to read the Dictionary tables, but for this example, I just hardcoded the values age, height and weight from SASHELP.CLASS.

Hopefully, this will give you a place to start. The output above is from the final PROC PRINT on WORK.ALLQUANT.

cynthia
[pre]
** 1) define the macro program;
%macro dovars(indsn=,
myvar=,
del_prev=n);

** clear out work.allquant if requested;
%if &del_prev = y %then %do;
proc datasets lib=work nodetails nofs nolist;
delete allquant;
run;
quit;
%end;

** run proc univariate on the data specified;
** for the variable specified;
PROC UNIVARIATE DATA=&indsn;
VAR &myvar;
OUTPUT OUT=WORK.q_&myvar
PCTLPRE=P_
PCTLPTS=0 to 100 by 5;
RUN;

** create the VARNAME variable;
data work.x;
length varname $32;
set work.q_&myvar;
varname = "&myvar";
run;

** make the final dataset by adding;
** this variable info to the prev runs;
proc append base=work.allquant
data=work.x;
run;

** clean up the work.x dataset;
proc datasets lib=work nodetails nofs nolist;
delete x;
run;
quit;

%mend dovars;

** 2) Use the macro program;
%dovars(indsn=sashelp.class, myvar=age, del_prev=y);
%dovars(indsn=sashelp.class, myvar=height, del_prev=n);
%dovars(indsn=sashelp.class, myvar=weight, del_prev=n);

options nocenter nodate nonumber;
proc print data=work.allquant;
title 'after running macro program';
run;
[/pre]
Ask a Question
Discussion stats
  • 1 reply
  • 1603 views
  • 0 likes
  • 2 in conversation