Probably a very newbie question, but I can't seem to get anything to work.
I have an existing dataset (got from someone else) with a column of "dates" with values such as 199301 (meaning January of 1993). The values appear to be stored as BEST 12, though, so that when I try to use them as dates I get a whole bunch of very funny results.
My understanding is that I need to change the numbers to characters and then read them back in as SAS dates, but haven't had any luck. I've tried code like the following, but either get errors or the new dates come out as missing:
D2 = input(put(yyyymm, Z6.) , YYMMDD6.);
Any ideas? Really, all I want to do is change the 199301 (stored as Best 12) into 199301 (stored as a date).
The underlying date will actually be January 1, 1993
Right idea though, wrong execution.
data have;
input date_num;
cards;
199301
199302
199303
199304
;
run;
data want;
set have;
date_format=input(put(date_num, 6. -l), yymmn6.);
format date_format yymmn6.;
run;
new_date=input(put(date,6.),yymmn6.);
Haikuo
Update: this will assume you the first day of the month. if you want some other days, you want to take a look at MDY() plus substr().
The underlying date will actually be January 1, 1993
Right idea though, wrong execution.
data have;
input date_num;
cards;
199301
199302
199303
199304
;
run;
data want;
set have;
date_format=input(put(date_num, 6. -l), yymmn6.);
format date_format yymmn6.;
run;
Thanks - worked like a charm.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: