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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 15011 views
  • 5 likes
  • 3 in conversation