I would like to use Arrays in a SAS Data Step as I need to apply the same method to a set of variables
However the method involves a SAS PROC.
My visualisation of the pseudo code is as follows:
data Percentile_output;
set Data12345
{array SQ definition here }
Do K = 1 to 60
Proc Univariate
Data = Data12345;
Output pctlpts = 20 40 60 80;
var SQ[k];
end;
run;
Output table:
sq01 sq02 ... sq60
p20 p20 p20
p40 p40 p40
p80 p80 p80
Any Suggestions?
No need ARRAY.
Proc Univariate Data = sashelp.class noprint;
var age weight height;
Output out=temp pctlpre=age_ weight_ height_ pctlpts = 20 40 60 80;
run;
proc transpose data=temp out=temp1;
run;
data temp2;
set temp1;
name=scan(_name_,1,'_');
pctl=scan(_name_,2,'_');
run;
proc transpose data=temp2 out=want;
by pctl;
id name;
var col1;
run;
Or It is very convenient for IML . Do you like it ?
proc iml;
use sashelp.class;
read all var{age weight height} into x[c=vnames];
close;
call qntl(q,x,{.2 .4 .6 .8});
print q[c=vnames r={p20 p40 p60 p80} l=''];
quit;
If the data is the same you only need a proc, since it can handle multiple variables at once. Unfortunately the data isn't in the form you want so a proc transpose is required to flip it.
@Ksharp code demonstrates this.
If you need to process different datasets then you use a macro.
There isn't a way to embed a proc inside a data step in the way you're envisioning.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.