Help using Base SAS procedures

Date with just month and year

Not applicable
Posts: 0

Date with just month and year

I have two variables: year (ie 2005-2009) and month (ie 1-12).
How can I create a date variable that displays, eg, Jan08 (or even better Jan-08)?
Thank you.
Super Contributor
Super Contributor
Posts: 3,176

Re: Date with just month and year

Posted in reply to deleted_user
In a DATA step, you will need to construct a suitable SAS character variable, one having a format that is suitable for any of the SAS-default INFORMATs. You can use the SUBSTR or possibly the SCAN function to parse your character values.

Here is an example:

1 data _null_;
2 retain year '2009-2005' month '1-12';
3 cmydate = scan(year,1,'-') !! '-' !! scan(month,1,'-') !! '-01';
4 format mydate date9.;
5 mydate = input(cmydate,yymmdd10.);
6 put _all_;
7 run;

year=2009-2005 month=1-12 cmydate=2009-1-01 mydate=01JAN2009 _ERROR_=0 _N_=1
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 second

Scott Barry
SBBWorks, Inc.
Not applicable
Posts: 0

Re: Date with just month and year

in place of this statement format mydate date9.;

use this:
format mydate monyy5.;

this will give you the "Jan09" output.

Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation