BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

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

 

 

12 REPLIES 12
PeterClemmensen
Tourmaline | Level 20
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.. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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!

data_null__
Jade | Level 19
tmp=input(cats(vvalue(renewal_date),"2018"),date9.);
Babloo
Rhodochrosite | Level 12

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

data_null__
Jade | Level 19
TMP is a SAS date. Give it a format like DATE9.
Babloo
Rhodochrosite | Level 12

if I do it, I will get numeric variable for TMP where as required output should be in character.

PaigeMiller
Diamond | Level 26

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
Babloo
Rhodochrosite | Level 12
No, it is appearing as numeric. Appreciate if you could provide me the
example if you disagree with me.
PaigeMiller
Diamond | Level 26

@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
PaigeMiller
Diamond | Level 26

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
Babloo
Rhodochrosite | Level 12

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.

ballardw
Super User

If you need a character variable:

 

tmp = put(renewal_date, date9.);

 

 

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!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 12 replies
  • 970 views
  • 0 likes
  • 6 in conversation