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!

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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