DATA Step, Macro, Functions and more

How to convert numeric date to SAS date

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

How to convert numeric date to SAS date

Hello,

 

I use SAS 9.4 and I have a variable "surveydate" (23AUG2011). Its length is 8, formats and informats are date9. and its type is numeric. Does anyone can tell me how to convert it to a SAS date so it shows "18862" instead of "23AUG2011"? I tried the following codes but it does not work.

 

data survey;

set survey;

survey_date=input(surveydate,date9.);

run;

 

Thank you!


Accepted Solutions
Solution
‎01-25-2017 02:01 PM
Trusted Advisor
Posts: 1,137

Re: How to convert numeric date to SAS date

I believe it is associated with the format, please remove the format as below

 

data survey;

set survey;

survey_date=input(surveydate,date9.);

format survey_date;

run;

Thanks,
Jag

View solution in original post


All Replies
Solution
‎01-25-2017 02:01 PM
Trusted Advisor
Posts: 1,137

Re: How to convert numeric date to SAS date

I believe it is associated with the format, please remove the format as below

 

data survey;

set survey;

survey_date=input(surveydate,date9.);

format survey_date;

run;

Thanks,
Jag
Contributor
Posts: 23

Re: How to convert numeric date to SAS date

Posted in reply to Jagadishkatam

Thanks Jag! I run the following codes and it worked well.

data survey;

set survey;

format survey_date;

run;

Super User
Super User
Posts: 7,050

Re: How to convert numeric date to SAS date

It is already is a number, in particular the number of days since 01JAN1960. It only looks to you like it is a date because you told SAS to use the DATE9. format to display it.  Either remove the format or attach different one.

 

data _null_;
   surveydate = '23aug2011'd ;
   put surveydate date9. ;
   put surveydate f9.;
   put surveydate comma9. ;
run;
Contributor
Posts: 23

Re: How to convert numeric date to SAS date

Thanks Tom! Your codes convert 23aug2011 into 18820 successfully and it is shown in the log.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 825 views
  • 5 likes
  • 3 in conversation