Hi,
I need to output a separat PDF plot file for each unit which aooear in my data set.
How can I make this simple and smart?????
The code below works but i need to loop it over the different units in the dataset so I output one plot per unit.
The dataset plot1 contains data for several units.
Hope you have some ideas.
Thanks in advance,
SAS program:
* data selection;
data plot1;
set masterdata(where=(year notin('2018') and unitname in(&unit.) )) other_sum;
run;
*make PDF file;
ods pdf file="C:/SGPLOT/&unit..pdf" notoc;
PROC SGPLOT DATA = plot1;
SERIES X = Reg_aar Y = var1/lineattrs=(color=green) ;
SERIES X = Reg_aar Y = var2 /lineattrs=(color=red) ;
SERIES X = Reg_aar Y =var3/lineattrs=(color=green pattern=dash) ;
SERIES X = Reg_aar Y =var4/lineattrs=(color=red pattern=dash);
yaxis values=(0 to 100 by 20);
TITLE 'Plot for &unit';
RUN;
ods pdf close;
You need to create a macro, and a %DO loop inside the macro.
Or, repeat the PROC SGPLOT code four times, and create only one SERIES statement in each repetition.
You need to create a macro, and a %DO loop inside the macro.
Or, repeat the PROC SGPLOT code four times, and create only one SERIES statement in each repetition.
This is a nice solution and it works as expected...Thanks
@ANLYNG wrote:
Hi,
I need to output a separat PDF plot file for each unit which aooear in my data set.
How can I make this simple and smart?????
The code below works but i need to loop it over the different units in the dataset so I output one plot per unit.
The dataset plot1 contains data for several units.
Hope you have some ideas.
Thanks in advance,
SAS program:
* data selection;
data plot1;
set masterdata(where=(year notin('2018') and unitname in(&unit.) )) other_sum;
run;
*make PDF file;
ods pdf file="C:/SGPLOT/&unit..pdf" notoc;
PROC SGPLOT DATA = plot1;
SERIES X = Reg_aar Y = var1/lineattrs=(color=green) ;
SERIES X = Reg_aar Y = var2 /lineattrs=(color=red) ;
SERIES X = Reg_aar Y =var3/lineattrs=(color=green pattern=dash) ;
SERIES X = Reg_aar Y =var4/lineattrs=(color=red pattern=dash);
yaxis values=(0 to 100 by 20);
TITLE 'Plot for &unit';
RUN;
ods pdf close;
First would be to change the data so that you have a single Y variable and another variable to indicate group membership. Use the Group=option to point to that variable to create different lines for each value of group.
SERIES X = Reg_aar Y = value/ group=ygroupvariable;
When you get that working then you could either use a macro loop over your list of variables to make the individual output PDF documents. However you haven't given us a connection between "unit" and your data so can't be too specific here.
This forum and others have many bits of looping over variable names to create files, table or graphs either using macro code or call execute statements with a control data set containing things such as your "unit" information.
If you change your SGPLOT procedure to use a BY statement you can use the NEWFILE option on the ODS PDF statement to generate a new file for each BY group.
However the naming convention sucks, it names it Report1, Report2.
If you want control over the file names then I think you need to use a macro.
Note that your Title statement needs double quotes to work properly. If you're using BY group processing look at customizing the title using the BYVAL values.
ods pdf file="C:/SGPLOT/Unit.pdf" notoc newfile=ByGroup;
PROC SGPLOT DATA = plot1;
By UNIT;
SERIES X = Reg_aar Y = var1/lineattrs=(color=green) ;
SERIES X = Reg_aar Y = var2 /lineattrs=(color=red) ;
SERIES X = Reg_aar Y =var3/lineattrs=(color=green pattern=dash) ;
SERIES X = Reg_aar Y =var4/lineattrs=(color=red pattern=dash);
yaxis values=(0 to 100 by 20);
TITLE "Plot for &unit";
RUN;
ods pdf close;
@ANLYNG wrote:
Hi,
I need to output a separat PDF plot file for each unit which aooear in my data set.
How can I make this simple and smart?????
The code below works but i need to loop it over the different units in the dataset so I output one plot per unit.
The dataset plot1 contains data for several units.
Hope you have some ideas.
Thanks in advance,
SAS program:
* data selection;
data plot1;
set masterdata(where=(year notin('2018') and unitname in(&unit.) )) other_sum;
run;
*make PDF file;
ods pdf file="C:/SGPLOT/&unit..pdf" notoc;
PROC SGPLOT DATA = plot1;
SERIES X = Reg_aar Y = var1/lineattrs=(color=green) ;
SERIES X = Reg_aar Y = var2 /lineattrs=(color=red) ;
SERIES X = Reg_aar Y =var3/lineattrs=(color=green pattern=dash) ;
SERIES X = Reg_aar Y =var4/lineattrs=(color=red pattern=dash);
yaxis values=(0 to 100 by 20);
TITLE 'Plot for &unit';
RUN;
ods pdf close;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: