DATA Step, Macro, Functions and more

sgplot with empty data

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

sgplot with empty data

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


Accepted Solutions
Solution
‎08-22-2017 09:33 AM
Super User
Posts: 10,046

Re: sgplot with empty data

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;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,934

Re: sgplot with empty data

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.

New Contributor
Posts: 4

Re: sgplot with empty data

Posted in reply to PaigeMiller

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

Super User
Super User
Posts: 7,997

Re: sgplot with empty data

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.

Solution
‎08-22-2017 09:33 AM
Super User
Posts: 10,046

Re: sgplot with empty data

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;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 98 views
  • 0 likes
  • 4 in conversation