- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
tried both of your solutions before. I can't make it an actual date value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.