BookmarkSubscribeRSS Feed
mich
Calcite | Level 5

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

4 REPLIES 4
mr_qwertzuiop_asdfghjkl
Calcite | Level 5

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

Astounding
PROC Star

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

proc sgplot data=have;

  by custid notsorted;

  ...

Good luck.

GraphGuy
Meteorite | Level 14

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;

ballardw
Super User

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1221 views
  • 0 likes
  • 5 in conversation