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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

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
Therain
Calcite | Level 5

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

data survey;

set survey;

format survey_date;

run;

Tom
Super User Tom
Super User

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;
Therain
Calcite | Level 5

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

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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