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

 

I am using SAS University Edition.  So I need to create a new column based on column x3.  The new column is yes/no  where 1 is yes and 0 is no.  If the value of column x3 is 50 or greater, the new column would indicate 1.  If it is less than 50, the new column would indicate no.  I have tried various ifelse statements and I cannot seem to get it to work.  I am novice to SAS, any help would be appreciated. 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
data work.data;
	set work.import;
run; /* this premature run statement terminates the step and causes the following statements to be invalid */
/* remove it */


if x3 > 49 then X7 = 1;
else if x3 < 50 then x7 = 0;
run;

View solution in original post

4 REPLIES 4
Shmuel
Garnet | Level 18

You should post your code, the log and explain what issues you have.

MarvelJJ
Calcite | Level 5

I am not sure how to get SAS to create the column with the data. I just keep getting errors.  

data work.data;
set work.import;
run;


if x3 > 49 then X7 = 1;
else if x3 < 50 then x7 = 0;
run;

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data work.data;
74 set work.import;
75 run;
 
NOTE: There were 50 observations read from the data set WORK.CRIME.
NOTE: The data set WORK.CRIME has 50 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
 
 
76
77
78 if x3 > 49 then X7 = 1;
__
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
79 else if x3 < 50 then x7 = 0;
____
180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
80 run;
81
82 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

 

Kurt_Bremser
Super User
data work.data;
	set work.import;
run; /* this premature run statement terminates the step and causes the following statements to be invalid */
/* remove it */


if x3 > 49 then X7 = 1;
else if x3 < 50 then x7 = 0;
run;
KachiM
Rhodochrosite | Level 12
data work.data;
	set work.import;
run;


if x3 > 49 then X7 = 1;
else if x3 < 50 then x7 = 0;
run;

Remove the inner "RUN" and test the program. It can also be written as:

data work.data;
	set work.import;
       x7 = 0;
     if x3 > 49 then X7 = 1;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1197 views
  • 0 likes
  • 4 in conversation