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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

2 REPLIES 2
Haikuo
Onyx | Level 15

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.

BlackTea
Calcite | Level 5

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1717 views
  • 4 likes
  • 3 in conversation