BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
in place of this statement format mydate date9.;

use this:
format mydate monyy5.;

this will give you the "Jan09" output.

Thanks,
Saurabh.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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