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!
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 25. 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.