BookmarkSubscribeRSS Feed
MisterJenn
Fluorite | Level 6

I am trying to figure out what I did wrong. I used the if, then statements to create a new variable "pubertal". 

 

libname hw5'\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Documents\Assignment 5';
data bone;
set hw5.bone (where =(sex=1));
age = (dov-dob)/365.25;
if tanner = '1' then pubertal = 0; 
else if tanner = '2' then pubertal = 0 or tanner = '3' then pubertal = 0; 
if tanner = '4' then pubertal = 1; 
else if tanner = '5' then pubertal = 1;
run; 
78   libname hw5'\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Documents\Assignment 5';
NOTE: Libref HW5 was successfully assigned as follows:
      Engine:        V9
      Physical Name: \\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Documents\Assignment 5
79   data bone;
80   set hw5.bone (where =(sex=1));
81   age = (dov-dob)/365.25;
82   if tanner = '1' then pubertal = 0;
83   else if tanner = '2' then pubertal = 0 or tanner = '3' then pubertal = 0;
                                                            ----
                                                            388
                                                            202
ERROR 388-185: Expecting an arithmetic operator.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

84   if tanner = '4' then pubertal = 1;
85   else if tanner = '5' then pubertal = 1;
86   run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      82:13   83:18   83:52   84:13   85:18
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.BONE may be incomplete.  When this step was stopped there were 0
         observations and 11 variables.
WARNING: Data set WORK.BONE was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds


2 REPLIES 2
Reeza
Super User
else if tanner = '2'  or tanner = '3' then pubertal = 0; 
else if tanner in ('2', '3') then pubertal=0;

ELSE statement has too many THEN portions.

 

Two options above for working on this are options you can use.


EDIT: 

If numeric, your code should be:

libname hw5'\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Documents\Assignment 5';
data bone;
set hw5.bone (where =(sex=1));
age = (dov-dob)/365.25;
if tanner in (1, 2, 3) then pubertal = 0; 
else if tanner in (4, 5) then pubertal = 1; 
run; 

Notes:

 

 

 

 


@MisterJenn wrote:

I am trying to figure out what I did wrong. I used the if, then statements to create a new variable "pubertal". 

 

libname hw5'\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Documents\Assignment 5';
data bone;
set hw5.bone (where =(sex=1));
age = (dov-dob)/365.25;
if tanner = '1' then pubertal = 0; 
else if tanner = '2' then pubertal = 0 or tanner = '3' then pubertal = 0; 
if tanner = '4' then pubertal = 1; 
else if tanner = '5' then pubertal = 1;
run; 
78   libname hw5'\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Documents\Assignment 5';
NOTE: Libref HW5 was successfully assigned as follows:
      Engine:        V9
      Physical Name: \\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Documents\Assignment 5
79   data bone;
80   set hw5.bone (where =(sex=1));
81   age = (dov-dob)/365.25;
82   if tanner = '1' then pubertal = 0;
83   else if tanner = '2' then pubertal = 0 or tanner = '3' then pubertal = 0;
                                                            ----
                                                            388
                                                            202
ERROR 388-185: Expecting an arithmetic operator.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

84   if tanner = '4' then pubertal = 1;
85   else if tanner = '5' then pubertal = 1;
86   run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      82:13   83:18   83:52   84:13   85:18
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.BONE may be incomplete.  When this step was stopped there were 0
         observations and 11 variables.
WARNING: Data set WORK.BONE was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds



 

ballardw
Super User

Are you sure that your Tanner variable is character? It appears that every comparison you have involving Tanner is creating the "converted to numeric" warning.

 

Such inattention to details can cause lots of issues further on.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 365 views
  • 2 likes
  • 3 in conversation