Reputation: 75
I am trying to use a series of if and else statements, for :
if var1 = 1 then var2 = "day 1";
else if var1 = 2 then var2 = "day 2";
The above bit works fine.
Then I have values for var1
of 1.1 and 1.2 and 2.1 etc. What I would like is that, if the value of var1
is of the format x.x (a value with one decimal place) then var2 = "No day assigned"
.
I am unsure how to program that in SAS?
Any pointers would be much appreciated.
Upvotes: 0
Views: 1043
Reputation: 7602
I would use the MOD function to determine if var1 is an integer or not. If your logic above applies to all values (i.e. the day number is the same as var1), then you can also simplify your if statements to a single line.
data test;
input var1;
length var2 $15;
var2=ifc(mod(var1,1)=0,cats('day ',var1),'No day assigned');
cards;
1
2
1.1
2.1
3
4
;
run;
Upvotes: 1