Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

Converting Date number to Date9.

Reply
Regular Contributor
Posts: 218

Converting Date number to Date9.

[ Edited ]

Hi,

 

I have a date1 variable with number (20140220) and I need to convert it to Date9. format (20FEB2014)

 

Any comments highly appreciated

 

 

Regards

SAS Super FREQ
Posts: 3,753

Re: Converting Date number to Date9.

One way is to convert the number to a character string and then use the INPUT function to apply a date format:

 

data A;
format d DATE9.;         /* display d as date */
date1 = 20140220;
c = put(date1, 8.);      /* convert to char */
d = input(c, anydtdte.); /* read with "anydate" format */
run;

proc print; run;
Super User
Super User
Posts: 7,060

Re: Converting Date number to Date9.

[ Edited ]

Since it is already a number you could convert the value to a SAS date value and apply the DATE9. format to the variable.

data want ;
    set have ;
    date1 = input(put(date1,8.),yymmdd8.);
    format date1 date9. ;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 246 views
  • 0 likes
  • 3 in conversation