I am trying to understand this, but always not getting to the key.Can any one help me with this..
infile ' C:\MYSAS\groups.dat';
input Name $ 1-5 group 6;
if group = . then new_grp = 'UNKNOWN';
else if group =1 then new_grp ='LOWER';
else if group=2 or 3 then new-grp='MEDIUM';
else new_grp= 'HIGHEST';
proc print data= New;
/***********END OF PROGRAM*************/
Q:-Now when I run this , what how is the value for new_grp variable only UNKNOWN, LOWER and MEDIUM??? Why isn't it considering the 'HIGH' value????
Below is the raw data file:groups.dat
It would be really helpful, if any one cud reply to this as soon as possible.
I do agree that 'or' always resolves for TRUE, but then what about the groups higher than 3. Like for instance even for group 6 , it is showing medium.????
Of course I can get the correct , desired answer in many ways(which also includes the one u said PROC FORMAT).
But I wanted to know whats happening with this code (which I sent)??
Is it bcoz of using the 'or' operator , it no more considers any other values????
I think you're missing the point here. Since SAS logic says that everything except the value of 0 resolves to TRUE, your OR 3 will always be TRUE, and therefore it will never go to your last ELSE statment, that will assign according to higher values than 2. So again, if you want your program to work, simply change your if statment to group in(2,3).
I don't think there is any coding problem, because I wanted to know if I write in this way , how would SAS react.. and one of our frnds Linus H (as u can see other replies) gave the explanation to this.
But what you said , gives the correct output though.