Hi All,
I want the dataset name to be created with year and month format,
ex.
ab002_201705 ,
data ab002_&sysyear&sysmonth is not giving desired result
First do the calculations in a data step, then save the result to a macro variable, and then use that for the dataset name:
data _null_;
myyear = year(today());
mymonth = month(today());
length string $6;
string = put(myyear,z4.) !! put(mymonth,z2.);
call symput('mymonth',string);
run;
%put "mymonth=&mymonth."; /* for control */
data ab002_&mymonth.;
This way you have full control over the formatting of the string.
First do the calculations in a data step, then save the result to a macro variable, and then use that for the dataset name:
data _null_;
myyear = year(today());
mymonth = month(today());
length string $6;
string = put(myyear,z4.) !! put(mymonth,z2.);
call symput('mymonth',string);
run;
%put "mymonth=&mymonth."; /* for control */
data ab002_&mymonth.;
This way you have full control over the formatting of the string.
Why. All that will do is make your coding efforts difficult. Either have one dataset with date as a column - this way you only have one dataset to program against but still have date information available - or have mutiple datasets, but call them something generic = ab002_1-ab002_xx - this way you can use lists of datasets, and short cuts to access them all (but having one dataset is far far simpler than anything else).
Do note that you might want "output" with the date on - this does not however define how you can work internally.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.