I'm using sgplot to produce some figures. Sometimes the input data is empty so sgplot won't produce an output figure. However, I want to use the output figure to proc report. If no figure is produced, the proc report will use previous sgplot figure. This is not I wanted.
How can you output an empty figure so my proc report won't use previous figures.
Thanks for the help
You can make a MACRO: %let dsid=%sysfunc(open(input)); %let nobs=%sysfunc(attrn(&dsid,nlobs)); %let dsid=%sysfunc(close(&dsid)); %if &nobs ne 0 %then %do; ods graphics / reset=INDEX height=5in width=6in imagefmt=png imagename="F" border=off; proc sgplot data=input ........................... %end; %else %do; proc sgplot data=DUMMY.............. %end;
However, I want to use the output figure to proc report
More information is needed. Do you mean "However, I want to use the output figure in proc report"? If so, how are you doing this? Show us the parts of your code that are relevant to using an output figure in PROC REPORT.
ods listing gpath='location' ; * store sgplot output in a folder
ods graphics / reset height=5in width=6in imagefmt=png imagename="F" border=off;
proc sgplot data=input * sometimes input is empty
ods listing close;
data image;
image="location\F1.png"; * BTW why I delcated my figure name as F, but the output name is F1?
run; * This is where the problem occurs, if no figure output from sgplot. it will take an old F1.png
quit;
proc report data=image
Not sure I follow, you can put graphs and reports in a file, but you can't proc report a graph?? If you want an empty graph if there is no data, just add a rows where there is data, but with 0,0 or whatever the lowest is so it has a point to plot.
ods rtf file="Final.rtf"; ods graphics...; /* If nobs is zero then create a file with one row of 0,0 */ data _null_; set sashelp.vtable (where=(libname="<yourlib>" and memname="<your ds>" and nobs=0)); call execute('data <yourlib>.<memname>; x=0; y=0; run;'); run; proc sgplot data=<yourlib>.<your ds>...; run; proc report data=somethingelse...; run; ods rtf close;
Note, replace yourlib and your ds with the relevant names of your libs and datasets, for where's it should be upper case.
You can make a MACRO: %let dsid=%sysfunc(open(input)); %let nobs=%sysfunc(attrn(&dsid,nlobs)); %let dsid=%sysfunc(close(&dsid)); %if &nobs ne 0 %then %do; ods graphics / reset=INDEX height=5in width=6in imagefmt=png imagename="F" border=off; proc sgplot data=input ........................... %end; %else %do; proc sgplot data=DUMMY.............. %end;
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 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.
Ready to level-up your skills? Choose your own adventure.