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

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.

 

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