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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 6 replies
  • 580 views
  • 6 likes
  • 4 in conversation