BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

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;
...
purpleclothlady
Pyrite | Level 9
Hi Kurt:
Dictionary.tables gave me the list of Data set name,
if I also need to get variable names containing "%DAT%" ,

proc sql noprint;
create table havecol as
select *
from dictionary.columns
where libname = "WORK" and memtype = "DATA" and name like '%DAT%';
quit;
Thanks
Purple
Tom
Super User Tom
Super User

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?

ballardw
Super User

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.;
purpleclothlady
Pyrite | Level 9
hi Ballardw:
Thanks for the suggestion. I will use the coalesce function.
Though the question might be why you are waiting to this step to create date values.-- I don't know what do you mean by this?
thanks
purple

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 19 replies
  • 1300 views
  • 3 likes
  • 5 in conversation