Hello.
I have some code I have found that will generate in a report if there are no observations in a data set. The problem is that this still generates above the report even if there are observations. I would like this to only run if there are no observations
PROC SQL NOPRINT;
SELECT NOBS INTO :Nbr_Obs
FROM DICTIONARY.TABLES
WHERE LIBNAME= 'work' AND MEMNAME= 'testdataset '
;
QUIT;
DATA NoObs;
testcolumnname = "No Data Today";
RUN;
PROC REPORT DATA=NoObs;
COLUMN status;
DEFINE status / center;
RUN;
If there are observations, I don't want DATA NoObs or PROC REPORT to RUN.
I have tried playing around with IF statments with no luck. To provide a little color, this is custom code I am adding to an Enterprise Guide Script instide a List Data task that generates the report. I don't think that is necessarily relevant as long as the code I am inserting is right.
I guess you want something like this:
%macro doTestDataSet;
PROC SQL NOPRINT;
SELECT NOBS INTO :Nbr_Obs
FROM DICTIONARY.TABLES
WHERE LIBNAME= 'work' AND MEMNAME= 'testdataset '
;
QUIT;
%if &Nbr_Obs > 0 %then %do;
DATA NoObs;
testcolumnname = "No Data Today";
RUN;
PROC REPORT DATA=NoObs;
COLUMN status;
DEFINE status / center;
RUN;
%end;
%else %do;
proc report data=testdataset;
... whatever ...
run;
%end;
%mend;
%doTestDataSet;
I guess you want something like this:
%macro doTestDataSet;
PROC SQL NOPRINT;
SELECT NOBS INTO :Nbr_Obs
FROM DICTIONARY.TABLES
WHERE LIBNAME= 'work' AND MEMNAME= 'testdataset '
;
QUIT;
%if &Nbr_Obs > 0 %then %do;
DATA NoObs;
testcolumnname = "No Data Today";
RUN;
PROC REPORT DATA=NoObs;
COLUMN status;
DEFINE status / center;
RUN;
%end;
%else %do;
proc report data=testdataset;
... whatever ...
run;
%end;
%mend;
%doTestDataSet;
@PGStats This worked perfectly. Thanks so much!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.