BookmarkSubscribeRSS Feed
Dsully19
Calcite | Level 5

Hi All,

 

 I have an input interval variable that has a range of negative and positive values. I want to transform the data so that all the negative values for this variable are changed to 0s. I connected my File Import node to the Rules Builder node and added the text below. Then I connected that to a Transform Variables node as I am changing some other variables, (not the ones I need to change the negative values to positives), then it is connected to a Data Partition Node and then a Stat Explore node. When I run everything and look at the results in the Stat Explore node I'm still seeing the negative values for the variables I need to change. Any idea what I'm doing wrong or how I can accomplish this? I appreciate all the help!

Dsully19_0-1661382420787.png

Dsully19_1-1661382451408.png

 

Rule in Rules Builder is...

 

EM_Outcome = "None";

IF Home_Team_Pitcher_s_FIP < 0.0 THEN DO;
EM_Outcome = "0";
END;
ELSE IF Visiting_Team_Pitcher_s_FIP < 0.0 THEN DO;
EM_Outcome = "0";
END;

 

6 REPLIES 6
ballardw
Super User

If Em_outcome variable is numeric you cannot assign character values such as "None" or "0".

Dsully19
Calcite | Level 5

@ballardw 

 

But if the Em_outcome variable is numeric, why wouldn't I be able to assign a numerical 0? Is there anyway that I can make the negative values 0 or no? 

Kurt_Bremser
Super User

By assigning character values like "None" or "0", you implicitly define the variable as character if it does not yet exist. If the variable exists and is numeric, then the data step compiler will compile an automatic conversion which will fail for the value of "None" at runtime (see the log for NOTEs and ERRORs). 

Kurt_Bremser
Super User

You are not changing existing variables, you create a new one which has the character value "0" when one of the incoming variables is negative.

To change an existing variable, do

home_team_pitcher_s_fip = max(home_team_pitcher_s_fip,0);
Dsully19
Calcite | Level 5

Hi All,

 

 I have an input interval variable that has a range of negative and positive values. I want to transform the data so that all the negative values for this variable are changed to 0s. I connected my File Import node to the Rules Builder node and added the text below. Then I connected that to a Transform Variables node as I am changing some other variables, (not the ones I need to change the negative values to positives), then it is connected to a Data Partition Node and then a Stat Explore node. When I run everything and look at the results in the Stat Explore node I'm still seeing the negative values for the variables I need to change. Any idea what I'm doing wrong or how I can accomplish this? I appreciate all the help!

Dsully19_0-1661386578398.png

 

Dsully19_1-1661386578401.png

 

 

Rule in Rules Builder is...

 

EM_Outcome = "None";

IF Home_Team_Pitcher_s_FIP < 0.0 THEN DO;
EM_Outcome = "0";
END;
ELSE IF Visiting_Team_Pitcher_s_FIP < 0.0 THEN DO;
EM_Outcome = "0";
END;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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