The SAS Output Delivery System and reporting techniques

Run Proc Report only if there are observations in a data set

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 141
Accepted Solution

Run Proc Report only if there are observations in a data set

[ Edited ]

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.


Accepted Solutions
Solution
‎05-24-2016 04:29 PM
Respected Advisor
Posts: 4,801

Re: Run Proc Report only if there are observations in a data set

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;
PG

View solution in original post


All Replies
Solution
‎05-24-2016 04:29 PM
Respected Advisor
Posts: 4,801

Re: Run Proc Report only if there are observations in a data set

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;
PG
Frequent Contributor
Posts: 141

Re: Run Proc Report only if there are observations in a data set

@PGStats This worked perfectly.  Thanks so much!

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 341 views
  • 1 like
  • 2 in conversation