BookmarkSubscribeRSS Feed
emaguin
Quartz | Level 8

This seems trivially simple but ...

I'm doing this, for example:

if (D1WEIGHT_3_TEXT eq "1 mixed drink") then D1WEIGHT_3_TEXT="1";
if (D1WEIGHT_3_TEXT eq "4ounces") then D1WEIGHT_3_TEXT="1";
if (D1WEIGHT_4_TEXT eq "4 ounces") then D1WEIGHT_4_TEXT="1";
if (D1WEIGHT_4_TEXT eq "48") then D1WEIGHT_4_TEXT="4";
if (D1WEIGHT_5_TEXT eq "0-2") then D1WEIGHT_5_TEXT="2";
if (D1WEIGHT_5_TEXT eq "1 1/4 ounces") then D1WEIGHT_5_TEXT="1";

 

followed by

A1ALCW3=INPUT(D1ALCWEEK_3_TEXT,BEST32.);
A1ALCW4=INPUT(D1ALCWEEK_4_TEXT,BEST32.);
A1ALCW5=INPUT(D1ALCWEEK_5_TEXT,BEST32.);

 

I'm getting this in the log

NOTE: Invalid argument to function INPUT at line 494 column 13. >>this location corresponds to an INPUT statement location<<

followed by a dump of the case. I'm not sure where the dump occurs, i.e., but i interpret the printout to mean that the recode failed and, of course, the conversion would fail. Ron Cody's book appears to be silent in recodes like i show so i don't have an example. It certainly could be that the search string doesn't match the target string but i'm working from a frequency table for each variable and data value appears to match the target string. So, i need some education.

Thanks, Gene Maguin

 

 

5 REPLIES 5
Reeza
Super User

If you show us the exact log it's easy to tell you where the error likely is. The log usually identifies it pretty exactly.

 

Also, are you familiar with IN? It helps makes these re-coding easier:

 

if D1WEIGHT_3_TEXT  in ("1 mixed drink", "4ounces") then 
                              D1WEIGHT_3_TEXT="1";

@emaguin wrote:

This seems trivially simple but ...

I'm doing this, for example:

if (D1WEIGHT_3_TEXT eq "1 mixed drink") then D1WEIGHT_3_TEXT="1";
if (D1WEIGHT_3_TEXT eq "4ounces") then D1WEIGHT_3_TEXT="1";
if (D1WEIGHT_4_TEXT eq "4 ounces") then D1WEIGHT_4_TEXT="1";
if (D1WEIGHT_4_TEXT eq "48") then D1WEIGHT_4_TEXT="4";
if (D1WEIGHT_5_TEXT eq "0-2") then D1WEIGHT_5_TEXT="2";
if (D1WEIGHT_5_TEXT eq "1 1/4 ounces") then D1WEIGHT_5_TEXT="1";

 

followed by

A1ALCW3=INPUT(D1ALCWEEK_3_TEXT,BEST32.);
A1ALCW4=INPUT(D1ALCWEEK_4_TEXT,BEST32.);
A1ALCW5=INPUT(D1ALCWEEK_5_TEXT,BEST32.);

 

I'm getting this in the log

NOTE: Invalid argument to function INPUT at line 494 column 13. >>this location corresponds to an INPUT statement location<<

followed by a dump of the case. I'm not sure where the dump occurs, i.e., but i interpret the printout to mean that the recode failed and, of course, the conversion would fail. Ron Cody's book appears to be silent in recodes like i show so i don't have an example. It certainly could be that the search string doesn't match the target string but i'm working from a frequency table for each variable and data value appears to match the target string. So, i need some education.

Thanks, Gene Maguin

 

 


 

ballardw
Super User

You may want to consider a custom informat to read the text directly into a numeric value.

Proc format library=work;
invalue ALC  (upcase)
"1 MIXED DRINK","4OUNCES","4 OUNCES" ,"1 1/4 OUNCES" = 1
"0-2"                                                = 2
"48"                                                 = 4
;
run;

data example;
   infile datalines dlm=',' dsd;
   informat alc alc.;
   input alc;
datalines;
"4ounces"
"4 ounces"
"48"
"0-2"
"1 1/4 ounces"
;

The upcase option tells SAS to make the string upper case before comparing with the values of the invalue list. That way you not have to have a separate entry for "4 ounces" "4 Ounces" "4 oUNCES" and all the possible combinations of upper and lower letters. You do unfortunately do need separate entries for the space and such

 

emaguin
Quartz | Level 8

Thank you for your replies.

I'm new to SAS from spss since the 80s so i'm learning. Although i've seen it described, I hadn't thought of the 'in' function. Yes, more compact. Nice.

 

Bigger context. Each of the variables, of which there are 7, have a mix of data values. Most data values are string numerics--'1', '10', '20', etc (A format)--but others are numeric-text combos, like what i posted. The 7 string variables need to get converted to new numeric variables and then they, the string vars, will be deleted. We want a numeric dataset for analysis. I've read about the format procedure in Cody's book and i don't really understand it. On one hand, it looks like an spss Recode command to change the numeric-text combos to string numerics plus an Alter type command to convert the string variable to a same-named numeric (F format) variable. But, there's the reference to the format library, which suggests there's not a new permanent variable created in the dataset. The dataset is a stand alone file that will be analyzed by anything--spss, stata, R, etc--that can read a sas data file. 

 

I provided the log error message. So, with respect to the error message, i need more specific guidance about what is needed. 

Gene Maguin

emaguin
Quartz | Level 8

Analyst error. Red face. Thank you for responding. 

Tom
Super User Tom
Super User

I'm getting this in the log

NOTE: Invalid argument to function INPUT at line 494 column 13. >>this location corresponds to an INPUT statement location<<

 

So which INPUT() function call did it indicate?  What text value was trying to be converted?  What informat was being used?

If you got an ERROR (and not just a note) then SAS will show the values of the variables for the observation that generated the error. 

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1682 views
  • 5 likes
  • 4 in conversation