BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
me55
Quartz | Level 8

okay, i have a pdf report i am trying to build.  it is...

 

options orientation=landscape;
ods pdf file="RTP03.pdf";

Title 'title 01';
Footnote Generated by &_CLIENTUSERNAME with SAS Enterprise Guide &_CLIENTVERSION;

proc sql;
select ...
from TEST01;
quit;

title;
footnote;

ods pdf close;

 

what i want it to do is to replace the sql pull into a macros that will check if a table (TEST01) has results in it that will be added from a insert into query.  if there are not results, put a line like 'there are no results' on the pdf and if the table has results, pull the data and put that on the pdf.  i have a macro set but i just cant finish it off yet.  i am just not knowledgeable enough in sas macros to finish this off...

 

%macro tblchk;

%let dsid=%sysfunc(open(TEST01));
%let nobs=%sysfunc(attrn(&dsid,nlobs));
%let dsid=%sysfunc(close(&dsid));

%if &nobs=0 %then %do;
%put There are no issues;
%end;

%else %do;
proc sql;
select *
from TEST01;
quit;
%end;

%mend tblchk;

 

something is just off here...i am just not sure what. 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Instead of

%if &nobs=0 %then %do;
%put There are no issues;
%end;

Try

%if &nobs=0 %then %do;
Proc odstext;
p "There are no results";
run;
%end;

%put writes to the log

Put can write to the log or a file but you will need to a bit more to create ODS output.

Simpler is to use a Proc designed to create ODS output.

If you want to make the text prettier you can add style elements to the P statements in Proc Odstext.

 

 

View solution in original post

4 REPLIES 4
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

 

%macro tblchk;
data _null_;
%let dsid=%sysfunc(open(TEST01));
%let nobs=%sysfunc(attrn(&dsid,nlobs));
%let dsid=%sysfunc(close(&dsid));
%if &nobs=0 %then %do;
%put There are no issues;
%end;
%else %do;
proc sql;
select *
from TEST01;
quit;
%end;
run;
%mend tblchk;

 

put a data null in the macro

 

me55
Quartz | Level 8

yeah, that is not working.  i should be able to replace the above sql in the report with the macro and have it either say there are no results or pull the results and that is not happening when i simply put the data _null_; in there...

 

ballardw
Super User

Instead of

%if &nobs=0 %then %do;
%put There are no issues;
%end;

Try

%if &nobs=0 %then %do;
Proc odstext;
p "There are no results";
run;
%end;

%put writes to the log

Put can write to the log or a file but you will need to a bit more to create ODS output.

Simpler is to use a Proc designed to create ODS output.

If you want to make the text prettier you can add style elements to the P statements in Proc Odstext.

 

 

me55
Quartz | Level 8

in case someone needs it, here is the final code that i settled on from the help of others and my searching for code...

 

options orientation=landscape;
options label nodate pageno=1;

ods escapechar='^';
ods pdf file=”RPT.pdf" startpage=no;


Title height=14pt underlin=1 'Reporting - Report';
Footnote Generated by &_CLIENTUSERNAME with SAS Enterprise Guide &_CLIENTVERSION;

ods pdf text = "^{style [just=center font=(Arial) fontsize=12pt fontweight=bold 
		color=black] Sub-Title}";

%macro tblchk;
data _null_;
%let dsid=%sysfunc(open(TABLE01));
%let nobs=%sysfunc(attrn(&dsid,nlobs));
%let dsid=%sysfunc(close(&dsid));

%if &nobs=0 %then %do;
proc odstext;
p 'There are NO Results!' / style=[color=red just=c fontsize=10pt fontweight=bold];
%end;

%else %do;
proc sql;
select *
from TABLE01;
quit;
%end;

%mend tblchk;
run;

%tblchk;
run;

 

thanks for the help as usual...

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 793 views
  • 0 likes
  • 3 in conversation