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.

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.

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 500 views
  • 0 likes
  • 2 in conversation