BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sasgorilla
Obsidian | Level 7

I have character variables that have numeric values, such as height and weight. To recode these as numeric, I made a new variable using the 'input' such as below. 

weightnew = input(weightold, 8.);

Functionally this works, but it also produces an error wherever there is a missing value for weightold. 

NOTE: Invalid argument to function INPUT at line 10516 column 10.
WARNING: Limit set by ERRORS= option reached.  Further errors of this type will not be printed.

This ultimately doesn't appear to matter as each of those missing character values becomes recoded as a missing numeric value, but the sight of all those errors in the log makes me worry something is wrong. 

 

Is there a better way to change weightold (character) to weightnew (numeric) than using the input statement?

 

Secondly, should I be bothered by the error log looking the way it does, or if it is doing what I want should I just ignore? 

 

Thanks. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here's a way to explore the data, to see which values are causing a problem:

proc freq data=have;
   tables weight;
   where input(weight, ??8.) = .;
run;

It might be that all the trouble-makers are "." or there might be a more troublesome situation such as substituting "O" for "0" some of the time.

View solution in original post

8 REPLIES 8
Cynthia_sas
SAS Super FREQ

Hi:

  I'd go back and look at your code more carefully. If your data is as you describe, then you should not have the INPUT function NOTE that you received. Are you sure your weights are standard numbers? I don't observe the same behavior with a test data table that has a character value for WEIGHTOLD and gets converted to a numeric variable WEIGHTNEW:

Cynthia_sas_0-1729127483196.png

  But you can force the INPUT note if your character string is not composed of standard numeric values. In the example below, the period is the thousands separator and the comma is the decimal separator, so I can see the NOTE in the log with a simple INFORMAT and I get rid of the NOTE using the COMMAX informat.

Cynthia_sas_1-1729128119850.png

Cynthia

ballardw
Super User

When there are known issues and you just want the log not to show invalid data you can use a modifier in the Input function:

 

data example;
   input weightold $;
   weightnew = input(weightold, ?? 8.);
datalines;
1.23
33lb
45.8
abc
;

Note the two question marks. They modify the Input to not display invalid data.

I would suggest not using this option unless you very sure of the reasons why you have values that can't be made numeric such as text like N/A entered in a source.

Patrick
Opal | Level 21

If you've got known strings like n/a that you want to convert to missings but also want to stay on the safe side and not just suppress any errors or warnings with the ?? modifier then you could also create your own informat using code similar to below.

proc format;
  invalue char2num
    'n/a' = .
    other = [best32.]
    ;
run;

data demo_1;
  infile datalines truncover;
  input charvar $;
  numvar_1=input(charvar,char2num32.);
  datalines;
11
2
n/a
4
;

data demo_2;
  infile datalines truncover;
  input charvar $;
  numvar_1=input(charvar,char2num32.);
  datalines;
11
2
n/a
4
xxx
;
Kurt_Bremser
Super User

Maxim 3: Know Your Data.

Your log should also have a listing of variable values when an "invalid" NOTE is issued.

Your variable weightold contains character data which cannot be converted by using the 8. informat.

Please show us those values.

Astounding
PROC Star

Here's a way to explore the data, to see which values are causing a problem:

proc freq data=have;
   tables weight;
   where input(weight, ??8.) = .;
run;

It might be that all the trouble-makers are "." or there might be a more troublesome situation such as substituting "O" for "0" some of the time.

sasgorilla
Obsidian | Level 7

Thankyou for your help, everyone! I accepted this as the solution since it helped me catch and clean few values that were contributing to the errors. 

 

One correction: your provided code would not run unless I eliminated one of the '?'. The code below is what worked for me. 

proc freq data=have;
   tables weight;
   where input(weight, ?8.) = .;
run;
Tom
Super User Tom
Super User

Yes. The WHERE statement is processed like an SQL statement.  And in that setting the functionality implied by the ?? modifier does not exist.

 

Also are you positive the character variable has a maximum length of only 8?  If not then you use of a width of 8 on the informat will ignore the end of the string.  Unless there is some reason you want it to ignore the ends of the string use the maximum width that the informat supports, which is 32.  The INPUT() function does not care if the width of the informat specification is larger than the length of the string being read.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 592 views
  • 6 likes
  • 7 in conversation