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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 951 views
  • 0 likes
  • 5 in conversation