Help using Base SAS procedures

Is it possible to reformat character to date?

Reply
Occasional Contributor
Posts: 17

Is it possible to reformat character to date?

Im trying to reformat column DateA to column DateB. The tricky part is there are characters in the column, ie "Not Applicable", so SAS is reading the whole column as character. I tried many different ways but they don't seem like working. So I wonder if it is possible to reformat date if there are characters in the column. 

 

Group DateA DateB
Group A 4/1/2016 04/01/2016
Group B 5/2/2016 05/02/2016
Group C 8/1/2016 08/01/2016
Group D 10/8/2016 10/08/2016
Group E Not Applicable Not Applicable
Group F 5/1/2016 05/01/2016
Group G Not Applicable Not Applicable
Group H 6/9/2016 06/09/2016
Group I Not Applicable Not Applicable
Group J 9/1/2016 09/01/2016
Group K 1/10/2016 01/10/2016
Super User
Posts: 17,898

Re: Is it possible to reformat character to date?

You can conditionally execute your code. This could be made a one-liner if you use ifn/ifc and/or if you apply ? to your input format, but I'll let you work those out Smiley Happy

 

if dateb='Not Applicable' then dateb_converted=.;

else dateb=input(dateb, mmddyy10.);

 

Super User
Super User
Posts: 7,413

Re: Is it possible to reformat character to date?

As Reeza has pointed out, conversion is pretty simple, and just drop the "Not" values.  However I would question firstly what those dates reflect, is it really MMDDYY, or DDMMYY?  Secondly why dates in DateA do not have the padding zero.  Looks a bit fishey if you ask me, I would check the source data.

Ask a Question
Discussion stats
  • 2 replies
  • 243 views
  • 0 likes
  • 3 in conversation