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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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