- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Could you please help me understand why I'm getting missing values in 'tmp' variable? This is the extract of the big piece of a program, so my objective is to know why I;m getting missing values in 'tmp'. What informat I should supply in input function
data test;
format renewal_date date5.;
renewal_date='09mar2018'd;
output;
renewal_date='09nov2018'd;
output;
renewal_date='19sep2018'd;
output;
run;
data test1;
set test;
tmp=input(cats(renewal_date,"2018"),date9.);
run;
Actual output:
renewal_date tmp
09MAR .
09NOV .
19SEP .
Desired Output:
renewal_date tmp
09MAR 09MAR 2018
09NOV 09NOV2018
19SEP 19SEP2018
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data test;
format renewal_date date5.;
renewal_date='09mar2018'd;
output;
renewal_date='09nov2018'd;
output;
renewal_date='19sep2018'd;
output;
run;
data test1;
set test;
format renewal_date date9.;
run;
Renewal_Date is already a numeric date variable, so no need to invoke character functions. Simply apply the appropriate format..
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Renewal_date is a numeric variable. It is a number of days since the cuttoff, regardless of what format is applied. When you use the value here:
tmp=input(cats(renewal_date,"2018"),date9.);
Your effectively saying
tmp=input(cats(<a number of days since a date>,"2018"),date9.);
Which is invalid, you need to put() the numeric into text:
tmp=input(cats(put(renewal_date,date5.),"2018"),date9.);
Remember numeric and text are different.
please also close out previous questions on exactly the same topic!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
tmp=input(cats(vvalue(renewal_date),"2018"),date9.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I tried your code, but it is not producing the desired output as per Original Post. Output which I got is as follows.
renewal_date tmp
09MAR 21252
09NOV 21497
19SEP 21446
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
if I do it, I will get numeric variable for TMP where as required output should be in character.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
When you give it a DATE9. format, it will appear as characters
But in fact, you don't need TMP at all, as others have pointed out, all you need to do is to assign the DATE9. format to your variable named RENEWAL_DATE.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
example if you disagree with me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Babloo wrote:
No, it is appearing as numeric. Appreciate if you could provide me the
example if you disagree with me.
When TMP shows as numbers, it does not have a format assigned to it. This is a pretty basic concept being demonstrated here, you have not assigned a format to TMP. Assign a format to tmp and it will appear as characters. If it doesn't work, then show us your code.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The CATS function tries to stick the text string 2018 at the end of your SAS date, which is a non-sensical thing to do. Your dates are already dates in 2018, and are SAS date values.
It's not really clear why you need TMP at all.
If the actual output shown is from PROC PRINT (is it?), then you just need to change the format of renewal_date so you can see the year.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
yes I know. But it's not the objective in our master program. I gave only the extract of the code which I need date and month as character in order to concatenate year value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you need a character variable:
tmp = put(renewal_date, date9.);