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!
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;
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! I run the following codes and it worked well.
data survey;
set survey;
format survey_date;
run;
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;
Thanks Tom! Your codes convert 23aug2011 into 18820 successfully and it is shown in the log.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.