BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_INFO
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

SAS_INFO
Quartz | Level 8
thank u , KurtBremsar
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sas-innovate-2024.png

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.

 

Register now!

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
  • 3 replies
  • 888 views
  • 1 like
  • 3 in conversation