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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 954 views
  • 0 likes
  • 2 in conversation