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.;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.