Hello,
last few hours I was fighting with something I was thinking will be easy, but I now I need you help.
I have data set that looks like this;
id start end
1 5 12
1 18 56
1 69 89
1 95 110
.
.
2 2 7
2 9 13
2 50 90
.
.
3 4 8
3 10 13
3 93 120
3 125 135
.
.
.
.
Start and end variables are actually beginning and end of a range. Maximum end value is 150 for all ids.
What I would like to have is id and var 1 to 150 with rages filled with 1, and things outside range filled with 0. Beginning and end of range should also be coded as 1.
so for example
id var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11 var12 var13 var14....var150
1 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0.......
2 0 1 1 1 1 1 1 0 1 1 1 1 1 0 0.....
3 0 0 0 1 1 1 1 1 0 0 1 1 1 0 0...
.
.
.
.
Thank you
Hi,
try the code below:
data have;
input id start end;
cards;
1 5 8
1 10 12
2 2 7
2 9 13
;
data temp;
set have;
array _var(*) var1-var150;
do i=1 to 150;
_var(i)=ifn(i ge start and i le end,1,0);
end;
proc summary data=temp nway missing ;
class id;
var var1-var150; ;
output out=want (drop=_:) max= ;
run;
proc print;run;
Hi,
try the code below:
data have;
input id start end;
cards;
1 5 8
1 10 12
2 2 7
2 9 13
;
data temp;
set have;
array _var(*) var1-var150;
do i=1 to 150;
_var(i)=ifn(i ge start and i le end,1,0);
end;
proc summary data=temp nway missing ;
class id;
var var1-var150; ;
output out=want (drop=_:) max= ;
run;
proc print;run;
looks great!
Thanks a lot?
What do think could I go for 150 000 000 variables?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.