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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 1063 views
  • 0 likes
  • 4 in conversation