Help using Base SAS procedures

Date Format

Reply
N/A
Posts: 0

Date Format

I am a new SAS user and was wondering how I would convert a date format that is 7FEB2008HH:MMSmiley FrustratedS to 200802. Any help will be great! Thanks.
Frequent Contributor
Posts: 95

Re: Date Format

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:MMSmiley FrustratedS
;
run;
[/pre]
Super Contributor
Posts: 291

Re: Date Format

I don't think you need to use the picture method. It looks like yymm7. should work for you (untested)

wd
Frequent Contributor
Posts: 91

Re: Date Format

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.;
Ask a Question
Discussion stats
  • 3 replies
  • 171 views
  • 0 likes
  • 4 in conversation