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

Hi,

I have a date variable with date9. format: 20FEB2014

I need to convert it to a number 20140220 and not a date.

Any comments highly appreciated

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data have;

date='20FEB2014'd;

date_want=input(put(date,yymmddn8.),best.);

run;

View solution in original post

6 REPLIES 6
ballardw
Super User

Couple ways:

funnydate= year(date)*10000 + month(date)*100 + day(date);

or

funnydate = input(put(date,yymmdd8.),best8.);

robertrao
Quartz | Level 8

Hi Ballard,

Thanks for the reply.

It would throw me an error as shown below.

The dater I have there is 20FEB2014. It's numeric and date9 format.

NOTE: Invalid argument to function INPUT at line 42 column 13.

Regards

stat_sas
Ammonite | Level 13

data have;

date='20FEB2014'd;

date_want=input(put(date,yymmddn8.),best.);

run;

robertrao
Quartz | Level 8

Thanks Stat,

It works. What is the logic behind putting n8.  ????

Regards

stat_sas
Ammonite | Level 13
Tom
Super User Tom
Super User

The YYMMDDN format is for displaying dates in ymd format without any separator character.  Using a length of 8 will force it to use 4 digits for the year.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1643 views
  • 6 likes
  • 4 in conversation