%macro populate_set_statement(current_date);
%let current_date_num = %sysfunc(inputn(¤t_date., yymmdd10.));
%let current_date_minus_363 = %eval(¤t_date_num - 363);
%let current_date_minus_347 = %eval(¤t_date_num - 347);
data all;
set
%do i = %sysfunc(inputn(20250317, yymmdd10.)) %to ¤t_date_num;
%if %sysfunc(exist(both_%sysfunc(putn(&i., mmddyy6.)))) %then both_%sysfunc(putn(&i., mmddyy6.));
%end;
%do j = ¤t_date_minus_363 %to ¤t_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.
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.
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.
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.
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.
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.
Ready to level-up your skills? Choose your own adventure.