DATA Step, Macro, Functions and more

Converting Character Date to Numeric Date

Accepted Solution Solved
Reply
Contributor
Posts: 52
Accepted Solution

Converting Character Date to Numeric Date

Hello SAS Supoort Communities,

I would like to convert the additional_signature_date_1 variable in the attached SAS dataset from a character variable to a numeric variable (a numeric SAS date).  I used the following code:
data audit.a2011p1;
set audit.a2011p;
date_var = input(additional_signature_date_1,date9.);
format date_var date9.;
run;
 
After running this, the date_var variable has a missing value (a dot) for each observation.  What should I change in my code?
 
God bless, best regards, and thanks so much,
Jadallah
Attachment

Accepted Solutions
Solution
‎09-20-2017 10:04 PM
Frequent Contributor
Posts: 100

Re: Converting Character Date to Numeric Date

[ Edited ]

Looking at obs=14 for the variable additional_signature_date_1='8/25/2011' - This is NOT date9. informat but mmddyy10 informat.  

 

Try this....

data audit.a2011p1;
set audit.a2011p;
date_var = input(additional_signature_date_1,mmddyy10.);
format date_var date9.;
run;

Always check your log, WARNING messages must be there or _ERROR_.

 

Hope this helps.

View solution in original post


All Replies
Solution
‎09-20-2017 10:04 PM
Frequent Contributor
Posts: 100

Re: Converting Character Date to Numeric Date

[ Edited ]

Looking at obs=14 for the variable additional_signature_date_1='8/25/2011' - This is NOT date9. informat but mmddyy10 informat.  

 

Try this....

data audit.a2011p1;
set audit.a2011p;
date_var = input(additional_signature_date_1,mmddyy10.);
format date_var date9.;
run;

Always check your log, WARNING messages must be there or _ERROR_.

 

Hope this helps.

Contributor
Posts: 52

Re: Converting Character Date to Numeric Date

Posted in reply to ShiroAmada

God bless you and your family!  Thank you so much!  I appreciate it!  It worked!

Frequent Contributor
Posts: 100

Re: Converting Character Date to Numeric Date

Amen PTLA (Praise The Lord Almighty).

 

You have a blessed day and coming weekend  jjadall1

Super User
Super User
Posts: 7,080

Re: Converting Character Date to Numeric Date

I am not going to download a zip file. Can you post some of the values of the charcter variable? Make sure to check whether the values have leading spaces.  For example you could run this data step to print the first 10 non-missing values.

data _null_;
  set audit.a2011p;
  where not missing(additional_signature_date_1);
  put additional_signature_date_1 $quote. ;
  if _n_ >= 10 then stop;
run;
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 145 views
  • 2 likes
  • 3 in conversation