BookmarkSubscribeRSS Feed
sasspan
Obsidian | Level 7

I have a variable with about 5 missing dates out of 250K claims.  I want to default this date to 01jan1900.  When I try this 

 

Case

when date is missing

then "01jan1900"d

else date

end 

 

It returns as a numeric variable.  When I try to put a PUT/INPUT around it to change it back to MMDDYY10. it will be blank all the way through.  Any help is appreciated. 

 

Thanks, 

 

Andrew 

7 REPLIES 7
novinosrin
Tourmaline | Level 20

If you want char

Case

when date is missing

then put( "01jan1900"d,date9.)

else date

end as var

if you want to just format to display the numeric

Case

when date is missing

then "01jan1900"d 

else date

end as var format=date9.
sasspan
Obsidian | Level 7
I don't want char or numeric. I want the result to be in date format. I've
tried both of your solutions before. I can't make it an actual date value.
novinosrin
Tourmaline | Level 20

Alright. Please clarify what do you mean by Actual date value.

 

SAS dates are continuous numbers(i,.e integers) starting from 0 on '01jan1960'd till date. You can use a format/in=format with put/input to either store the dates as char or read char to num respectively.

 

 

PaigeMiller
Diamond | Level 26

SAS variables have to be either character or numeric.


If you want it to be in DATE9. format, then it must be a numeric variable.

--
Paige Miller
ballardw
Super User

If you want a missing value to appear as a specific string then create a custom format that assigns such.

 

But the answers you have made to other posts tell me it is time for you to share actual input data and what  you actually expect to be the data values. It appears that you may be confuse as this doesn't make much sense:
to change it back to MMDDYY10

 

Change what? Perhaps you need an explicit format assignment:

Case

   when missing(date) then "01jan1900"d
   else date
end  as date format=mmddyy10.
Tom
Super User Tom
Super User

@sasspan wrote:

I have a variable with about 5 missing dates out of 250K claims.  I want to default this date to 01jan1900.  When I try this 

 

Case

when date is missing

then "01jan1900"d

else date

end 

 

It returns as a numeric variable.  When I try to put a PUT/INPUT around it to change it back to MMDDYY10. it will be blank all the way through.  Any help is appreciated. 

 

Thanks, 

 

Andrew 


The CASE block is making a NEW variable, it will not retain any attributes of the original DATE variable. So if you want a specific FORMAT attached to the variable you need to tell SAS that.  Same thing if you want a specific LABEL attached to this new variable.

case .... end as new_varname format=yymmdd10.

PS Try to avoid M-D-Y or D-M-Y order for dates. Which ever one you pick will confuse half of you audience.  Stick with DATE9 or YYMMDD10 formats to avoid misunderstandings.

ballardw
Super User

@Tom wrote:

PS Try to avoid M-D-Y or D-M-Y order for dates. Which ever one you pick will confuse half of you audience.  Stick with DATE9 or YYMMDD10 formats to avoid misunderstandings.


@Tom Let's not forget the wonderful Julian date: 19262 for today! ( Really wanted one of the "devil" emoticons to go with this one).

 

 

 

For those Julian date impaired that date is the same as 18Sep2019 (or 18 September of any year that isn't a leap year) . Julian dates are number of day in the year preceded by a 2 or 4 digit year.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 7 replies
  • 14175 views
  • 2 likes
  • 5 in conversation