BookmarkSubscribeRSS Feed
mj262716
Calcite | Level 5

Hi,

 

I am trying to create a new variable from information already in my data set.  I used an if then statement to do so, however the code is reading but it will not make it a new variable in my data set.  When I try to use a Acecutoff variable later in my code, it tells me it is not found.  When I do proc print then it variable has a a triangle looking shape with an A inside of it, not a circle with a number let the rest.  It would be greatly appreciated if someone could tell me where I am going wrong.

 

data aces2;
set b.aces;

if ACE_SCORE >=4.0 then
Acecutoff="4 or greater";
else if ACE_SCORE <3.0 then
Acecutoff="less than 4";
run;

proc print;
run;

 

2 REPLIES 2
Tom
Super User Tom
Super User

Your code looks fine (other than not handling all possible values).  Are you sure you are looking at the right dataset? Did you check your log for errors?

data aces ;
 id+1;
 input ace_score ;
cards;
1
2
3
4
5
;

data aces2;
 	set aces;
 	if ACE_SCORE >=4.0 then	Acecutoff="4 or greater";
 	else if ACE_SCORE <3.0 then	Acecutoff="less than 4";
run;

proc print;
run;
              ace_
Obs    id    score     Acecutoff

 1      1      1      less than 4
 2      2      2      less than 4
 3      3      3
 4      4      4      4 or greater
 5      5      5      4 or greater
epniv
Obsidian | Level 7
As Tom suggested, the logic of your if/then is flawed.
>= 4 will give you 4 & 5
< 3 will never define 3
You need < 4 to complete the logic

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

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 1066 views
  • 2 likes
  • 3 in conversation