DATA Step, Macro, Functions and more

Nesting put and input functions in SAS

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

Nesting put and input functions in SAS

Hi,

I'm trying to convert dates from 20160221 to 02/21/2016 format for a variable "Createdon". I used input and put function together to do it but I'm getting the results with a NOTE:

Mathematical operations could not be performed at the following places. The results of

the operations have been set to missing values.

Each place is given by: (Number of times) at (Line)Smiley SadColumn).

2060 at 198:27

 

the code I used is

data new;

set test;

CREATEDON_0CREATEDON=input(put(CREATEDON_0CREATEDON,z8.),yymmdd8.);

format CREATEDON_0CREATEDON mmddyy10.;

run;

 

I see the output the way I wanted (02/12/2016) but I get that NOTE as well. How can I make sure that I run the programm without any Notes in the log.

 

Thank you

Malathi

 

 


Accepted Solutions
Solution
‎01-26-2017 08:53 AM
Super User
Posts: 17,745

Re: Nesting put and input functions in SAS

old_date = ifn(old_date ne ., input(put(old_date, z8.), ?? yymmdd8.), .);

Malathi13 wrote:

Hi Reeza,

That's the full code and I'm using proc import to import the file with a libname statement. Only issue I have is to get rid of that NOTE in the  log that looks like this:

 

130

131 data n.new;

132 set n.test;

133 CREATEDON_0CREATEDON=input(put(CREATEDON_0CREATEDON,z8.),yymmdd8.);

134 format CREATEDON_0CREATEDON mmddyy10.;

135 *format CREATEDON_0CREATEDON yymmdd10.;

136 if DOC_NUMBER_0DOC_NUMBER eq 'ROW_COUNT' then delete;

137 run;

NOTE: Invalid argument to function INPUT at line 133 column 22.

DOC_NUMBER_0DOC_NUMBER=ROW_COUNT S_ORD_ITEM_0S_ORD_ITEM=2060 SOLD_TO_0SOLD_TO=.

MCK_ID_0CUSTOMER=. CREATEDON_0CREATEDON=. FILE_CRT_DT_0DATE=0 FILE_CRT_TIME_0TIME=0

ORDER_METHOD_ZSPPOTYP= CREATEDBY_0CREATEDBY= REF_ID_0GT_BSTKD= ORD_REASON_0ORD_REASON=

REASON_REJ_0REASON_REJ= MATERIAL_0MATERIAL=. NDC_ZNDCNUMBR=. NDC_DESC_0TXTMD=

ORD_QTY_0CML_OR_QTY=0.000 UOM_0UNIT= FREE_IND_0FLAG= DEL_BLOCK_0DEL_BLOCK=

SHIPTO_STREET_0STREET= SHIPTO_STR_SUPPL1_0STR_SUPPL1= SHIPTO_CITY_0CITY=

SHIPTO_REGION_0REGION= SHIPTO_POSTAL_CD_0POSTAL_CD= SOLDTO_NAME2_0NAME2=

REFER_DOC_0REFER_DOC=. REFER_ITM_0REFER_ITM=0 DOC_TYPE_0DOC_TYPE= ITEM_CATEG_0ITEM_CATEG=

EXT_WAC_0SUBTOTAL_1=0 NET_VAL_0NET_VALUE=0 DISCOUNT_0SUBTOTAL_1=0 DISC_PCT_0SUBTOTAL_1=0

UNIT_WAC_0SUBTOTAL_1=0 SHIP_TO_0SHIP_TO=. SHIP_TO_NAME_0NAME______=,,,,,, _ERROR_=1 _N_=2061

NOTE: Mathematical operations could not be performed at the following places. The results of

the operations have been set to missing values.

Each place is given by: (Number of times) at (Line)Smiley SadColumn).

1 at 133:22

NOTE: There were 2061 observations read from the data set N.TEST.

NOTE: The data set N.NEW has 2060 observations and 36 variables.

NOTE: DATA statement used (Total process time):

real time 0.01 seconds

cpu time 0.01 seconds

 

Thank you

Malathi


 

Look at the red highlighted portions. It shows that you have missing values and that's causing the issues. You need to add an IF condition to not process the missing values OR use ?? in the INPUT to suppress the errors. 

 

Suppress the notes:

 

old_date = input(put(old_date, z8.), ?? yymmdd8.);

 

 

Avoid calculation:

old_date = ifn(old_date ne ., input(put(old_date, z8.), yymmdd8.), .);

 

View solution in original post


All Replies
Super User
Posts: 17,745

Re: Nesting put and input functions in SAS

Please post your full code and log. I cannot replicate your issue, based on the information you've provided. This means it's either something you're not telling us or something else in your code that's causing the issues.

 

data check;
input old_date;
old_date = input(put(old_date, z8.), yymmdd8.);
format old_date date9.;
cards;
20160221
20170105
;
run;

proc print;
run;

Contributor
Posts: 46

Re: Nesting put and input functions in SAS

Hi Reeza,

That's the full code and I'm using proc import to import the file with a libname statement. Only issue I have is to get rid of that NOTE in the  log that looks like this:

 

130

131 data n.new;

132 set n.test;

133 CREATEDON_0CREATEDON=input(put(CREATEDON_0CREATEDON,z8.),yymmdd8.);

134 format CREATEDON_0CREATEDON mmddyy10.;

135 *format CREATEDON_0CREATEDON yymmdd10.;

136 if DOC_NUMBER_0DOC_NUMBER eq 'ROW_COUNT' then delete;

137 run;

NOTE: Invalid argument to function INPUT at line 133 column 22.

DOC_NUMBER_0DOC_NUMBER=ROW_COUNT S_ORD_ITEM_0S_ORD_ITEM=2060 SOLD_TO_0SOLD_TO=.

MCK_ID_0CUSTOMER=. CREATEDON_0CREATEDON=. FILE_CRT_DT_0DATE=0 FILE_CRT_TIME_0TIME=0

ORDER_METHOD_ZSPPOTYP= CREATEDBY_0CREATEDBY= REF_ID_0GT_BSTKD= ORD_REASON_0ORD_REASON=

REASON_REJ_0REASON_REJ= MATERIAL_0MATERIAL=. NDC_ZNDCNUMBR=. NDC_DESC_0TXTMD=

ORD_QTY_0CML_OR_QTY=0.000 UOM_0UNIT= FREE_IND_0FLAG= DEL_BLOCK_0DEL_BLOCK=

SHIPTO_STREET_0STREET= SHIPTO_STR_SUPPL1_0STR_SUPPL1= SHIPTO_CITY_0CITY=

SHIPTO_REGION_0REGION= SHIPTO_POSTAL_CD_0POSTAL_CD= SOLDTO_NAME2_0NAME2=

REFER_DOC_0REFER_DOC=. REFER_ITM_0REFER_ITM=0 DOC_TYPE_0DOC_TYPE= ITEM_CATEG_0ITEM_CATEG=

EXT_WAC_0SUBTOTAL_1=0 NET_VAL_0NET_VALUE=0 DISCOUNT_0SUBTOTAL_1=0 DISC_PCT_0SUBTOTAL_1=0

UNIT_WAC_0SUBTOTAL_1=0 SHIP_TO_0SHIP_TO=. SHIP_TO_NAME_0NAME______=,,,,,, _ERROR_=1 _N_=2061

NOTE: Mathematical operations could not be performed at the following places. The results of

the operations have been set to missing values.

Each place is given by: (Number of times) at (Line)Smiley SadColumn).

1 at 133:22

NOTE: There were 2061 observations read from the data set N.TEST.

NOTE: The data set N.NEW has 2060 observations and 36 variables.

NOTE: DATA statement used (Total process time):

real time 0.01 seconds

cpu time 0.01 seconds

 

Thank you

Malathi

Solution
‎01-26-2017 08:53 AM
Super User
Posts: 17,745

Re: Nesting put and input functions in SAS

old_date = ifn(old_date ne ., input(put(old_date, z8.), ?? yymmdd8.), .);

Malathi13 wrote:

Hi Reeza,

That's the full code and I'm using proc import to import the file with a libname statement. Only issue I have is to get rid of that NOTE in the  log that looks like this:

 

130

131 data n.new;

132 set n.test;

133 CREATEDON_0CREATEDON=input(put(CREATEDON_0CREATEDON,z8.),yymmdd8.);

134 format CREATEDON_0CREATEDON mmddyy10.;

135 *format CREATEDON_0CREATEDON yymmdd10.;

136 if DOC_NUMBER_0DOC_NUMBER eq 'ROW_COUNT' then delete;

137 run;

NOTE: Invalid argument to function INPUT at line 133 column 22.

DOC_NUMBER_0DOC_NUMBER=ROW_COUNT S_ORD_ITEM_0S_ORD_ITEM=2060 SOLD_TO_0SOLD_TO=.

MCK_ID_0CUSTOMER=. CREATEDON_0CREATEDON=. FILE_CRT_DT_0DATE=0 FILE_CRT_TIME_0TIME=0

ORDER_METHOD_ZSPPOTYP= CREATEDBY_0CREATEDBY= REF_ID_0GT_BSTKD= ORD_REASON_0ORD_REASON=

REASON_REJ_0REASON_REJ= MATERIAL_0MATERIAL=. NDC_ZNDCNUMBR=. NDC_DESC_0TXTMD=

ORD_QTY_0CML_OR_QTY=0.000 UOM_0UNIT= FREE_IND_0FLAG= DEL_BLOCK_0DEL_BLOCK=

SHIPTO_STREET_0STREET= SHIPTO_STR_SUPPL1_0STR_SUPPL1= SHIPTO_CITY_0CITY=

SHIPTO_REGION_0REGION= SHIPTO_POSTAL_CD_0POSTAL_CD= SOLDTO_NAME2_0NAME2=

REFER_DOC_0REFER_DOC=. REFER_ITM_0REFER_ITM=0 DOC_TYPE_0DOC_TYPE= ITEM_CATEG_0ITEM_CATEG=

EXT_WAC_0SUBTOTAL_1=0 NET_VAL_0NET_VALUE=0 DISCOUNT_0SUBTOTAL_1=0 DISC_PCT_0SUBTOTAL_1=0

UNIT_WAC_0SUBTOTAL_1=0 SHIP_TO_0SHIP_TO=. SHIP_TO_NAME_0NAME______=,,,,,, _ERROR_=1 _N_=2061

NOTE: Mathematical operations could not be performed at the following places. The results of

the operations have been set to missing values.

Each place is given by: (Number of times) at (Line)Smiley SadColumn).

1 at 133:22

NOTE: There were 2061 observations read from the data set N.TEST.

NOTE: The data set N.NEW has 2060 observations and 36 variables.

NOTE: DATA statement used (Total process time):

real time 0.01 seconds

cpu time 0.01 seconds

 

Thank you

Malathi


 

Look at the red highlighted portions. It shows that you have missing values and that's causing the issues. You need to add an IF condition to not process the missing values OR use ?? in the INPUT to suppress the errors. 

 

Suppress the notes:

 

old_date = input(put(old_date, z8.), ?? yymmdd8.);

 

 

Avoid calculation:

old_date = ifn(old_date ne ., input(put(old_date, z8.), yymmdd8.), .);

 

Contributor
Posts: 46

Re: Nesting put and input functions in SAS

Hi Reeza,

Thank you so much, when I used ?? in th einput function it worked. Thanks a lot.

 

Malathi

Super User
Posts: 10,466

Re: Nesting put and input functions in SAS

I can recreate a similar message with this code:

data example;
   input CREATEDON_0CREATEDON;
datalines;
20160221
20161131
20161410
0160221
.
999990101
;
run;

data want;
   set example;
   x= CREATEDON_0CREATEDON;
   CREATEDON_0CREATEDON=input(put(CREATEDON_0CREATEDON,z8.),yymmdd8.);
   format CREATEDON_0CREATEDON mmddyy10.;
run;

But you may want to pay attention to more of the log:

 

NOTE: Invalid argument to function INPUT at line 856 column 25.
CREATEDON_0CREATEDON=. x=20161131 _ERROR_=1 _N_=2
NOTE: Invalid argument to function INPUT at line 856 column 25.
CREATEDON_0CREATEDON=. x=20161410 _ERROR_=1 _N_=3
NOTE: Invalid argument to function INPUT at line 856 column 25.
CREATEDON_0CREATEDON=. x=999990101 _ERROR_=1 _N_=6
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
      missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      3 at 856:25

Any value that cannot be considered a valid date will generate that error.

 

I do not understand the use of the Z8 format. If you have a value that does not have 8 digits then you have moved the value to a year prior to 1585 and the SAS data conversions do not go that far back and can generate that error. You would be better off checking the range of the value and if it is less than something reasonable for your project such as 19000101 then treat that differently. You may need to parse to get year/month/day and supply an assumed date or use a different infomat. If you want 201601, without a day of month, to be treated as jan 1, 2016 then you may want to attempt to read with a yymm6. format which assumes the day is 01.

Super User
Posts: 6,928

Re: Nesting put and input functions in SAS

Don't nest the function calls. Create a new character variable with put(...,z8.) and use that in the input(...,yymmdd8.). That way you can see in the log which value causes the problem. Drop the intermediate variable if you don't want it in the dataset.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 233 views
  • 1 like
  • 4 in conversation