Help using Base SAS procedures

Informats and Dates

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Informats and Dates

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


Accepted Solutions
Solution
‎03-12-2014 03:09 PM
Super User
Posts: 17,868

Re: Informats and Dates

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


All Replies
Respected Advisor
Posts: 3,124

Re: Informats and Dates

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

Solution
‎03-12-2014 03:09 PM
Super User
Posts: 17,868

Re: Informats and Dates

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;

Contributor
Posts: 35

Re: Informats and Dates

Thanks - worked like a charm.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 209 views
  • 3 likes
  • 3 in conversation