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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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