Help using Base SAS procedures

SAS DATES

Reply
Super Contributor
Posts: 1,041

SAS DATES

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

Super User
Posts: 5,498

Re: SAS DATES

Posted in reply to robertrao

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.

Super Contributor
Posts: 1,041

Re: SAS DATES

Posted in reply to Astounding

I mean putting

8/1999

Super User
Posts: 5,498

Re: SAS DATES

Posted in reply to robertrao

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.);

Ask a Question
Discussion stats
  • 3 replies
  • 188 views
  • 0 likes
  • 2 in conversation