DATA Step, Macro, Functions and more

Executing a PROC from a DATA Step

Reply
Contributor
Posts: 59

Executing a PROC from a DATA Step

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?

Super User
Posts: 9,676

Re: Executing a PROC from a DATA Step

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

Contributor
Posts: 59

Re: Executing a PROC from a DATA Step

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. -##
Super User
Posts: 17,819

Re: Executing a PROC from a DATA Step

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. 

Ask a Question
Discussion stats
  • 3 replies
  • 243 views
  • 1 like
  • 3 in conversation