Help using Base SAS procedures

looping sas procedure

Reply
Occasional Contributor
Posts: 12

looping sas procedure

Hi,

i have a data table where each row is a customer information, i want to run a procedure (for example Proc gplot) for each customer so for each row.

how can i do that without writing the Proc gplot as many times as the number of customers (actually i have thousands of rows)?

Thank you

Michel

Occasional Learner
Posts: 1

Re: looping sas procedure

Try this:

data work.loop;

infile datalines;

input col1 $;

datalines;

x

y

z

;

run;

data work.data;

infile datalines;

input col1 $ col2;

datalines;

x 1

y 2

z 3

;

run;

%macro loop(txt);

proc print data=work.data (where=(col1="&txt.")); run;

%mend;

%macro readds;

%let dsid = %sysfunc(open(work.loop,in));

%let nobs = %sysfunc(attrn(&dsid,nlobs));

%put nobs=&nobs;

%do i = 1 %to &nobs;

  %let rc = %sysfunc(fetch(&dsid,'NOSET'));

  %let col1 = %sysfunc(getvarc(&dsid,%sysfunc(varnum(&dsid,col1))));

  %put col1=&col1;

  %loop(&col1)

%end;

%let rc = %sysfunc(close(&dsid));

%mend;

%readds

Super User
Posts: 5,092

Re: looping sas procedure

If the report format comes out OK, you could try:

proc sgplot data=have;

  by custid notsorted;

  ...

Good luck.

SAS Employee
Posts: 967

Re: looping sas procedure

When I do this, I put my graph code in a macro (such as %do_graph), and then loop through the items in a data step, and 'call execute' the macro each time through...

/* Loop through, and make a plot for each manufacturer */

proc sql noprint;

create table loopdata as

select unique statecode

from my_data;

quit; run;

data _null_;

set loopdata;

   call execute('%do_graph('|| statecode ||');');

run;

Super User
Posts: 10,538

Re: looping sas procedure

I find most graphs made with a single point to be less than optimum for most uses...

You may end up restructuring data to get a good result from SAS graphical procs compared with  the choices you may make with Excel or similar programs.

Ask a Question
Discussion stats
  • 4 replies
  • 260 views
  • 0 likes
  • 5 in conversation