Seems like an over complication to generate multiple macro variables. Do you have more than a thousand datasets? You can fit 65K characters into a single macro variable.
proc sql noprint;
select distinct newmem into :dsnames separated by ' '
from havecol
;
quit;
data temp.have;
length source $41;
set &dsnames indsname=indsname;
SOURCE=indsname;
...
Thanks.
Now take another step back in the process. Where did the datasets in the WORK library come from?
Were they copied from some other SAS libref? Why were they copied?
Were they generated by some program? Why did the program not generate DATE variable to begin with?
Were they created from some non-SAS files? What type of files? If they were text files why not generate the dates when the files were read?
I have to say that whenever I see code like this involving Put and concatenation followed by an Input that someone doesn't know the right function. The MDY function takes a numeric month, day and year parameter to return a date.
So I suspect that
&fvar= mdy(coalesce(&v1._mm,1),coalesce(&v1._dd,1), &v1._yyyy);
(The Coalesce function returns the first non-missing value in the list of parameters. So is an easy way to avoid "if not missing then do.)
accomplishes the same thing as that ugly code.. Though the question might be why you are waiting to this step to create date values.
if &v1._dd ^=. then &ovar.=put(&v1._yyyy, 4.)||'-'||put(&v1._mm, z2.)||'-'||put(&v1._dd, z2.); else if &v1._mm ^=. then &ovar.=put(&v1._yyyy, 4.)||'-'||put(&v1._mm, z2.)||'-01'; else if &v1._yyyy^=. then &ovar.=put(&v1._yyyy, 4.)||'-01'||'-01'; &fvar.=input(&ovar.,yymmdd10.); format &fvar. yymmdd10.;
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 25. Read more here about why you should contribute and what is in it for you!
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.