BookmarkSubscribeRSS Feed
Deepti44
Fluorite | Level 6

SAS Experts ,

 

I have  around 3 graphs created in each page for each customer, now i have around 25 customers where i need to create 3 graphs per page per customer.I tried to use do loops but it is not working.

 

Can i know how to append the graphs to each individual page ( 3 graphs Per page) per customer.

 

Appreciate your help on this.

3 REPLIES 3
Reeza
Super User

Post what you've tried so far. Maybe you're really close.

Deepti44
Fluorite | Level 6

I have tried this below code  with do loop , but need to find a  way on how to append the graph per page for each customer.

 

%MACRO GRAPH;


%do i=1 %to &COUNT1. %by 1;
%put &&CASE_OWNER&i;


options symbolgen;


%macro delcat(catname);

%if %sysfunc(cexist(&catname))
%then %do;
proc greplay nofs igout=&catname;
delete _all_;
run;
quit;
%end;
%mend delcat;

%delcat(work.gseg)

%let outdir=%trim(%sysfunc(pathname(work)));

options orientation=landscape nodate nonumber;

goptions reset=all;
title 5 'Graph for &&CASE_OWNER&i';

/* This step uses multiple PROC SGPLOT procedures */
/* to write multiple PNG files to disk. Note that */
/* this step uses the IMAGENAME= option on the ODS */
/* GRAPHICS ON statement to name each PNG file */
/* that is written to disk. */

ods _all_ close;
ods listing gpath="&outdir" image_dpi=300;

ods graphics on / reset=index imagename='sgplot1'
width=5in height=3.8in;

title1 'First SGPLOT Output';
proc sgplot data=final_v3;
title 'Active Status by Month Created';
vbar CREATED_MONTH / group=REALTIME_OPEN_CASESTATUS groupdisplay=cluster dataskin=gloss;
where case_owner=&&CASE_OWNER&i;
xaxis display=(nolabel);
yaxis grid;
run;


ods graphics on / reset=index imagename='sgplot2'
width=5in height=3.8in;

title1 'Second SGPLOT Output';
proc sgplot data=final_v3;
title 'Case Status by Created Month';
vbar CREATED_MONTH / group=STATUS groupdisplay=cluster dataskin=gloss;
where case_owner=&I;
xaxis display=(nolabel);
yaxis grid;
run;


ods graphics on / reset=index imagename='sgplot3'
width=5in height=3.8in;

title1 'Third SGPLOT Output';

proc sgplot data=final_v3;
title 'Case Reason Distribution';
vbar CASE_REASON / group=REALTIME_OPEN_CASESTATUS groupdisplay=cluster dataskin=gloss;
where case_owner=&I;
xaxis display=(nolabel);
yaxis grid;
run;

 


/*ods graphics on / reset=index imagename='sgplot4' */
/* width=5in height=3.8in;*/
/**/
/*title1 'Fourth SGPLOT Output';*/
/*proc sgplot data=sashelp.class; */
/* vbar age / response=height stat=mean; */
/* where sex="M"; */
/*run; */

ods listing;

/* This step uses PROC GSLIDE with the IBACK= and */
/* IMAGESTYLE= graphics options to read the PNG */
/* files created in step 1 back into SAS. */
goptions reset=all device=png300 nodisplay
xmax=5in ymax=3.8in;

goptions iback="&outdir./sgplot1.png" imagestyle=fit;
proc gslide;
run;
quit;

goptions iback="&outdir./sgplot2.png" imagestyle=fit;
proc gslide;
run;
quit;

goptions iback="&outdir./sgplot3.png" imagestyle=fit;
proc gslide;
run;
quit;

/*goptions iback="&outdir./sgplot4.png" imagestyle=fit; */
/*proc gslide; */
/*run;*/
/*quit;*/

/* This final step uses PROC GREPLAY to put four */
/* SGPLOT outputs on the same PDF page. */
goptions reset=all device=sasprtc;

ods listing close;
ods pdf file="&outdir./greplay_sgplot.pdf" notoc dpi=300;

proc greplay igout=work.gseg nofs tc=sashelp.templt
template= U2D1;
treplay 1:1 2:3 3:2 ;
run;
quit;

ods pdf close;
ods listing;


%END;

%MEND GRAPH;

%GRAPH;

Reeza
Super User

 

You should start with working code for one customer and then create the macro from there ideally. 

Add a WHERE statement to filter each plot for each customer

 

Then add another loop to create the graphs for each customer. This assumes your previous loop works and was doing something specific.

 

Make sure the ODS PDF statement has the customer ID in it as well, to generate a new file for each customer. 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 3 replies
  • 1302 views
  • 2 likes
  • 2 in conversation