BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello:

 

I have a code below,  and I received an error message from log.  Please advice how to fix it, thanks.

 

data want;

set have;

if stateid ^=. then productID+1;

ERROR 400-185: The SUM statement requires numeric expression.

run; 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@ybz12003 wrote:

I have tried both of the codes, none of them was working.  All of the StateID are numeric.

 

925 data allstaterename1; set allstaterename;

926 If mrs_stateid ^=. then momID+1;

-

400

ERROR 400-185: The SUM statement requires numeric expression.

927 /* If not missing (nad_stateid) then childID+2;*/ run;

 

 

928 data allstaterename1; set allstaterename;

929 /*If mrs_stateid ^=. then momID+1;*/

930 If not missing (nad_stateid) then childID+2; run;

-

400

ERROR 400-185: The SUM statement requires numeric expression.

 


You cannot use the SUM statement like:

momID+1;
childID+1;

with character variables.

So either use a different variable name.

momID_number+1;
childID_number+1;

Or use the DROP= or RENAME= dataset options on the input dataset to get the old variable out of the way.

 set allstaterename(drop=momID);
 set allstaterename(rename=(momID=old_momID));

View solution in original post

10 REPLIES 10
PeterClemmensen
Tourmaline | Level 20

productID seems to be a character variable. convert it to numeric using the INPUT function 🙂

 

http://sasnrd.com/convert-character-numeric/

 

data_null__
Jade | Level 19

@PeterClemmensen wrote:

productID seems to be a character variable. convert it to numeric using the INPUT function 🙂


 

I don't think that will work.

PaigeMiller
Diamond | Level 26

@data_null__ wrote:

@PeterClemmensen wrote:

productID seems to be a character variable. convert it to numeric using the INPUT function 🙂


 

I don't think that will work.


Of course, the original poster has not told us what ProductID contains, but it is highly suspicious from a logical point of view that adding one to productID makes any sense at all.

--
Paige Miller
ybz12003
Rhodochrosite | Level 12

There is no ProductID column in the table 'have',   I would like to create one when the StateID is not blank, and the new generated column ProductID is the same as StateID.  Thanks.

ballardw
Super User

@ybz12003 wrote:

There is no ProductID column in the table 'have',   I would like to create one when the StateID is not blank, and the new generated column ProductID is the same as StateID.  Thanks.


That sounds like:

 

If not missing(stateid) then ProductId=StateId;

 

Again, showing input data and desired output may clarify what you are actually attempting.

Tom
Super User Tom
Super User

@ybz12003 wrote:

There is no ProductID column in the table 'have',   I would like to create one when the StateID is not blank, and the new generated column ProductID is the same as StateID.  Thanks.


If that is true the the error is for the other variable in your statement.

if stateid ^=. then productID+1;

Your code is treating STATEID as if it was a number, so SAS tried to convert the value to a number.  

Use the MISSING() function which does not care what type of variable you give it.

If not missing(stateid) then ProductId+1;

But if you want PRODUCTID to be the same as STATEID it seems you just want.

 

ProductId = coalescec(stateid,ProductId);
ybz12003
Rhodochrosite | Level 12

I have tried both of the codes, none of them was working.  All of the StateID are numeric.

 

925 data allstaterename1; set allstaterename;

926 If mrs_stateid ^=. then momID+1;

-

400

ERROR 400-185: The SUM statement requires numeric expression.

927 /* If not missing (nad_stateid) then childID+2;*/ run;

 

 

928 data allstaterename1; set allstaterename;

929 /*If mrs_stateid ^=. then momID+1;*/

930 If not missing (nad_stateid) then childID+2; run;

-

400

ERROR 400-185: The SUM statement requires numeric expression.

 

Tom
Super User Tom
Super User

@ybz12003 wrote:

I have tried both of the codes, none of them was working.  All of the StateID are numeric.

 

925 data allstaterename1; set allstaterename;

926 If mrs_stateid ^=. then momID+1;

-

400

ERROR 400-185: The SUM statement requires numeric expression.

927 /* If not missing (nad_stateid) then childID+2;*/ run;

 

 

928 data allstaterename1; set allstaterename;

929 /*If mrs_stateid ^=. then momID+1;*/

930 If not missing (nad_stateid) then childID+2; run;

-

400

ERROR 400-185: The SUM statement requires numeric expression.

 


You cannot use the SUM statement like:

momID+1;
childID+1;

with character variables.

So either use a different variable name.

momID_number+1;
childID_number+1;

Or use the DROP= or RENAME= dataset options on the input dataset to get the old variable out of the way.

 set allstaterename(drop=momID);
 set allstaterename(rename=(momID=old_momID));
PaigeMiller
Diamond | Level 26

Great, you have tried the code suggested.

 

Now, let's go further ... it was also suggested that you SHOW US YOUR DATA (or at least, a relevant portion of your data). I think that's the only way we are going to get you an answer.

--
Paige Miller
ybz12003
Rhodochrosite | Level 12

Thanks for everone's prompt replies and great suggestions.  It works. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 10 replies
  • 2523 views
  • 3 likes
  • 6 in conversation