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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

2 REPLIES 2
PGStats
Opal | Level 21

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
elwayfan446
Barite | Level 11

@PGStats This worked perfectly.  Thanks so much!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 2390 views
  • 1 like
  • 2 in conversation