Help using Base SAS procedures

Converting Character into SAS dates

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Converting Character into SAS dates

Hi Guys,

I currently have dates which are characters.

196507

196508

196509

.

.

In YYMM, where they have format and informat as $6.

I would like to convert them into SAS dates so that I can work on them easily. I.e. remain as196507, 196508, 196509...... but are in the SAS dates with format and informat YYMMN6.

I tried the following code but it doesn't seem to work:

DATA OUT;

SET IN;

DATENEW= INPUT (DATE, YYMMN6.)

RUN;

196508 becomes 2039

196509 become 2070... ...

Thanks for the help guys!


Accepted Solutions
Solution
‎01-03-2013 10:28 AM
Respected Advisor
Posts: 3,156

Re: Converting Character into SAS dates

Can't repeat your issue on SAS 9.3.

data want;

  input date $6.;

  DATENEW= INPUT (DATE, YYMMN6.);

  format datenew date9.;

  put "datenew=" datenew;

  cards;

196507

196508

196509

  ;

Haikuo

UPdate: I see what is going on: the number you are seeing is the day count from 1/1/1960, it is how SAS store its date variable, you would need to assign a format to see the conventional date that we are using in everyday life.

View solution in original post


All Replies
Solution
‎01-03-2013 10:28 AM
Respected Advisor
Posts: 3,156

Re: Converting Character into SAS dates

Can't repeat your issue on SAS 9.3.

data want;

  input date $6.;

  DATENEW= INPUT (DATE, YYMMN6.);

  format datenew date9.;

  put "datenew=" datenew;

  cards;

196507

196508

196509

  ;

Haikuo

UPdate: I see what is going on: the number you are seeing is the day count from 1/1/1960, it is how SAS store its date variable, you would need to assign a format to see the conventional date that we are using in everyday life.

Occasional Contributor
Posts: 10

Re: Converting Character into SAS dates

Benn must add the format statement to see the internal date value as he wants.

2039 and 2070 and so on in the number since 01JAN1960. Readin the SAS Online doc in the chapter 

About SAS Date, Time, and Datetime Values

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 740 views
  • 4 likes
  • 3 in conversation