BookmarkSubscribeRSS Feed
MisterJenn
Fluorite | Level 6

Not sure what his error code is showing me. 

error code 

11   data fram_merge;
12   merge fram1_temp fram2_temp;
13   by subjid;
14   age = (vdate-bdate)/365.25;
15   diff_tchol = totchol2 - totchol;
16   if diff_tchol > 1 then ch_tchol > 1;
                            --------
                            180
17   else if diff_tchol < 1 then ch_tchol < 1;
                                 --------
                                 180
ERROR 180-322: Statement is not valid or it is used out of proper order.

18   if diff_tchol = 0 then chtchol = 0;
19   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FRAM_MERGE may be incomplete.  When this step was stopped there were 0
         observations and 12 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

 

proc sort data=fram1_temp; by subjid;
proc sort data=fram2_temp; by subjid; 
data fram_merge;
merge fram1_temp fram2_temp;
by subjid;
age = (vdate-bdate)/365.25;
diff_tchol = totchol2 - totchol;
run;
data fram_merge; 
if diff_tchol > 1 then ch_tchol > 1; 
else if diff_tchol < 1 then ch_tchol < 1;
if diff_tchol = 0 then ch_tchol = 0;
run;

Here is what I am trying to answer

  • Create a variable called ch_tchol which equals –, 0, or + depending on whether diff_tchol is negative, zero, or positive in value respectively.

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Logically, I don't even understand what the statement is supposed to be doing, but it is a SAS syntax error.

 

if diff_tchol > 1 then ch_tchol > 1;

 

You could do something like this with an equal sign:

 

if diff_tchol > 1 then ch_tchol = 1;

 

 

which avoids the SAS error, but it may not be what you want, and I am not any closer to understanding what you are trying to do logically. Could you explain what the logic is that you are trying to implement in SAS?

 

 

--
Paige Miller
MisterJenn
Fluorite | Level 6
Essentially this is what I am trying to do: Create a variable called ch_tchol which equals –, 0, or + depending on whether diff_tchol is negative, zero, or positive in value respectively.
PaigeMiller
Diamond | Level 26

@MisterJenn wrote:
Essentially this is what I am trying to do: Create a variable called ch_tchol which equals –, 0, or + depending on whether diff_tchol is negative, zero, or positive in value respectively.

A numeric variable can't have a value of – or +, but it can have values of –1 or +1. So, here you go:

 

ch_tchol = sign(diff_tchol);

 

 

This is different than what you tried to program, in which the cutoffs for diff_tchol was +1, but it is what you just said.

 

 

 

--
Paige Miller
Kurt_Bremser
Super User

"-" and "+" are not numeric, but character values, so it seems your new variable needs to be of type character.

if diff_tchol > 0
then ch_tchol = "+";
else if diff_tchol = 0
then ch_tchol = "0";
else ch_tchol = "-";
ballardw
Super User

Personally I wouldn't bother with creating an additional variable after you have the values of diff_tchol.

I would use a custom format to show the values desired.

proc format ;
value sign
low -<0 = '-'
0       = '0'
0 <- High='+'
;
run;

data example;
   input x;
datalines;
-4
.05
0
-.0001
10000000
;

proc print data=example;
   var x;
   format x sign.;
run;

The groups created by a format will be honored by reporting or analysis procedures and most graph procedures.

Also the -, 0, and + would sort in that order. Character values will generally be in a different order and quite often not the one you may want.

Your code also missed any possibility that the difference might be between -1 and 0 or 0 and 1 .

Another reason to consider a format is if you have multiple variables to do this sort of thing with one format can be applied to multiple variables and you do not have to create a separate character value for each. Might be something to consider if you have 50 values that you want to display as -,0,+.

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 16. 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
  • 5 replies
  • 460 views
  • 0 likes
  • 4 in conversation