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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.