DATA Step, Macro, Functions and more

Executing a PROC from a DATA Step

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];




Output table:

sq01  sq02  ... sq60

p20   p20          p20

p40   p40         p40


p80   p80        p80


Any Suggestions?

Super User
Posts: 10,389

Re: Executing a PROC from a DATA Step

Posted in reply to JonDickens1607

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;
proc transpose data=temp out=temp1;
data temp2;
 set temp1;
proc transpose data=temp2 out=want;
 by pctl;
 id name;
 var col1;


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];

call qntl(q,x,{.2 .4 .6 .8});

print q[c=vnames r={p20 p40 p60 p80} l=''];


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.


##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 21,924

Re: Executing a PROC from a DATA Step

Posted in reply to JonDickens1607

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
  • 1 like
  • 3 in conversation