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
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
If the report format comes out OK, you could try:
proc sgplot data=have;
by custid notsorted;
...
Good luck.
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.