Subscribe to DSC Newsletter

Hi all,
How would you translate this SAS array example into R? What i am trying to do is to create a flag variable based on a calculation within the defined array x. *The columns I have are x0, the array variables x1-x5 and the flag that i want to create named flag

data df1;
set df;
array x {5} x1 - x5;
do i=1 to 5;
if x0=x{i} then do;
flag=i;
leave;
end;
end;
drop i;
run;

I have search practically everywhere but i can t seem to find something similar, i know that i could use sqldf with multiple case when statements or the if then else but the thing is that the array have 5 columns now in the future it might have 20 ,30,50 so additional statements have to be written.


Thanks in advance

Views: 398

Reply to This

On Data Science Central

© 2019   AnalyticBridge.com is a subsidiary and dedicated channel of Data Science Central LLC   Powered by

Badges  |  Report an Issue  |  Privacy Policy  |  Terms of Service