BookmarkSubscribeRSS Feed
JonDickens1607
Obsidian | Level 7

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?

3 REPLIES 3
Ksharp
Super User

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;

x.png

JonDickens1607
Obsidian | Level 7
Thank you for your reply to my question.

I will check each suggested solution and then confirm.

Regards

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Reeza
Super User

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. 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1419 views
  • 1 like
  • 3 in conversation