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

Hi all,

%Let mon - Dec2011 ;

I want to use the above macro variable in a data step and create a month end  date variable in date9. format (like 31DEC2011) . Is there a easy way to do it?

Data a;

date9 = 31dec2011(this is what i want to see in column date9.)

Run;

Thanks in advance for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

First learn about date literals to make it easier to use the macro variable.  You could write "01&mon"d to represent the first of the month.

Then learn about the INTNX function for how to convert a date.  You want to use MONTH interval and find the END of the interval.

%let mon=Dec2011;

data a;

  date9 = intnx('month',"01&mon"d,0,'end');

  format date9 date9.;

  put "mon=&mon " date9= ;

run;

mon=Dec2011 date9=31DEC2011

You can also do this in macro logic if you need it.

%let d=dec2011;

%let e=%sysfunc(intnx(month,"01&d"d,0,e),date9.);

%put e=&e;

e=31DEC2011

%let d=feb2012;

%let e=%sysfunc(intnx(month,"01&d"d,0,e),date9.);

%put e=&e;

e=29FEB2012

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

First learn about date literals to make it easier to use the macro variable.  You could write "01&mon"d to represent the first of the month.

Then learn about the INTNX function for how to convert a date.  You want to use MONTH interval and find the END of the interval.

%let mon=Dec2011;

data a;

  date9 = intnx('month',"01&mon"d,0,'end');

  format date9 date9.;

  put "mon=&mon " date9= ;

run;

mon=Dec2011 date9=31DEC2011

You can also do this in macro logic if you need it.

%let d=dec2011;

%let e=%sysfunc(intnx(month,"01&d"d,0,e),date9.);

%put e=&e;

e=31DEC2011

%let d=feb2012;

%let e=%sysfunc(intnx(month,"01&d"d,0,e),date9.);

%put e=&e;

e=29FEB2012

vicky07
Quartz | Level 8

Thanks!!

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
  • 2 replies
  • 729 views
  • 0 likes
  • 2 in conversation