BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jteague
Calcite | Level 5

%macro populate_set_statement(current_date);


    %let current_date_num = %sysfunc(inputn(&current_date., yymmdd10.));
    %let current_date_minus_363 = %eval(&current_date_num - 363);
    %let current_date_minus_347 = %eval(&current_date_num - 347);

    data all;
        set
            %do i = %sysfunc(inputn(20250317, yymmdd10.)) %to &current_date_num;
                %if %sysfunc(exist(both_%sysfunc(putn(&i., mmddyy6.)))) %then both_%sysfunc(putn(&i., mmddyy6.));
            %end;
            %do j = &current_date_minus_363 %to &current_date_minus_347;
                %if %sysfunc(exist(all22_%sysfunc(putn(&j., mmddyy6.)))) %then all22_%sysfunc(putn(&j., mmddyy6.));
            %end;
        ;
    run;

%mend populate_set_statement;
%populate_set_statement(%sysfunc(today(), yymmdd10.));

 

Using SAS 9.4 (TS1M7).

I have this part of a program that auto populates a dataset "all" based on dates. There is a chance in the future that some of the datasets used to create the datasets in the set statement above will be empty causing All not to be created. Can someone give me a work around so that if a dataset is empty it is removed from the set statement? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

When you say some of the datasets are empty, you mean some of them have 0 records?  That should not stop your dataset work.ALL from being created.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.

View solution in original post

2 REPLIES 2
Quentin
Super User

When you say some of the datasets are empty, you mean some of them have 0 records?  That should not stop your dataset work.ALL from being created.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.
jteague
Calcite | Level 5

Thank you. You are right and I was confused. When testing the code the issue was datasets that do not exist rather than ones with zero observations. But that shouldn't be an issue the way the code above this is written. So thanks again.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 248 views
  • 0 likes
  • 2 in conversation