BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yeaforme
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

3 REPLIES 3
Haikuo
Onyx | Level 15

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().

Reeza
Super User

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;

yeaforme
Calcite | Level 5

Thanks - worked like a charm.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 926 views
  • 3 likes
  • 3 in conversation