BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

I have a macrovariable

and i want to convert it to a numeric date and store it for the entire dataset

%let monthyear=Aug1999;

In the below the WANT table should have numeric AUG 1999

data want;

set have;

run;

Thanks

3 REPLIES 3
Astounding
PROC Star

There is no such thing as a single numeric value that corresponds to all of August 1999.  Numeric SAS dates correspond to a single day. 

You can save it as a character variable in this fashion:

monyr = "&monthyear";

Or you can save it as a numeric variable representing a particular day:

monyr = "01&monthyear"d;

If you prefer some other date other than the first of the month, that's obviously easy to change.

Good luck.

robertrao
Quartz | Level 8

I mean putting

8/1999

Astounding
PROC Star

OK, this code could be used:

num_date = "01&monthyear"d;

length char_date $ 7;

char_date = left(  put(month(num_date),2.) || '/' || put(year(num_date),4.)  );

My recommendation would be to alter the result slightly, using a leading zero for months prior to October:

char_date = put(month(num_date),z2.) || '/' || put(year(num_date),4.);

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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