BookmarkSubscribeRSS Feed
sashelp123
Calcite | Level 5

Hello, I am having an issue with something in SAS (version 9.4) and could use some expertise! Basically my macro currently looks like this:

 

proc sql;

select count(*) into: thirtyfive_counts

from history_upi, dummy_upi_clean, dummy_upi_76, history_upi_76;

quit;

%macro yyy(when);

%if &when ne 0 %then %do;

%include 'G:\Groups\HHR\new 35 file.sas';

%end;

%mend;

%yyy(&thirtyfive_counts);

 

Ultimately, I want this program(in the include statement) to be run if there are any records in any of those 4 datasets (listed in the from statement). The issue I am having is if one of those datasets is empty (which will sometimes be the case) it is giving me an error and not running the program. However, if I only list the datasets where this is a record, it will work fine. I would like it to run if there is an observation in any of the four datasets. Is this possible?

Thanks!

 

1 REPLY 1
Kurt_Bremser
Super User
%let thirtyfive_counts=0;
proc sql no print;
select sum(nobs) into: thirtyfive_counts
from dictionary.tables
where libname = 'WORK' and lowercase(memname) in
("history_upi","dummy_upi_clean","dummy_upi_76","history_upi_76");
quit;

is the correct way to determine this. If none of these datasets exists, you still get a zero.

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 937 views
  • 1 like
  • 2 in conversation