BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am a new SAS user and was wondering how I would convert a date format that is 7FEB2008HH:MM:SS to 200802. Any help will be great! Thanks.
3 REPLIES 3
1162
Calcite | Level 5
I'm not strong on date formats, but I came up with this suggestion:

I didn't see a built-in SAS date format that you could use, so maybe you can create a picture format using
[pre]
proc format library=work;
picture mydate low-high = '%Y0%m' (datatype=date);
run;
[/pre]

If the date is already in SAS as a date formated value (I think you missed a colon after the year), then you could just apply the picture format . . .
[pre]
data work.date;
format date_in mydate6.;
date_in = '7FEB2008:10:27:59'd;
run;
[/pre]

Then, if the date is literally what you've written, then I would select the date part from this text string and reformat that to the picture format.
[pre]
data work.date;
input date_txt $24.;
format date_new mydate6.;
date_new = input(scan(date_txt,1,"H"), date9.);
cards;
7FEB2008HH:MM:SS
;
run;
[/pre]
Bill
Quartz | Level 8
I don't think you need to use the picture method. It looks like yymm7. should work for you (untested)

wd
advoss
Quartz | Level 8
Do you want to create the datetime value to a new variable with just the date portion, or are you only interested in displaying the year/month portion of the datetime? If the latter, then you'll need to do the picture format as suggested by Christopher. If the former, then you can do something like:

justdate = datepart(dtvar);
format justdate yymmn6.;

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 2746 views
  • 0 likes
  • 4 in conversation