Hello all,
II need to compare a variable (y1) to a subset of the same variable (y2) to generate a binary variable (beta). is there a clever way of doing this without having missing data?
Many thanks,
y1 | y2 |
28 | 28 |
15.5 | 15.5 |
8.2 | 8.2 |
3.4 | 3.4 |
17.3 | 17.3 |
15.2 | 15.2 |
32.9 | 32.9 |
11.1 | 11.1 |
87.5 | |
16.2 | |
107.9 | |
5.7 | |
25.6 | |
31.2 | |
21.6 | |
55.6 | |
8.8 | |
6.5 | |
22.1 | |
14.4 | |
44.2 | |
3.7 | |
7.8 | |
8.9 | |
719 | |
2106.667 | |
24000 | |
1715 | |
3.6 | |
521.5 | |
1600 | |
454 | |
109.7 |
proc sql;
create table temp as
select
a.y1 as compare_y1,
b.y2 as compare_y2,
a.y1 <= b.y2 as beta
from training as a, training as b;
quit;
data training;
input y1 y2;
datalines;
28 28
15.5 15.5
8.2 8.2
3.4 3.4
17.3 17.3
15.2 15.2
32.9 32.9
11.1 11.1
87.5
16.2
107.9
5.7
25.6
31.2
21.6
55.6
8.8
6.5
22.1
14.4
44.2
3.7
7.8
8.9
719
2106.667
24000
1715
3.6
521.5
1600
454
109.7
;
run;
proc sql;
create table temp as
select
a.y1 as compare_y1,
b.y2 as compare_y2,
a.y1 <= b.y2 as beta
from training as a, training as b;
quit;
Are you after this?
data want;
set training(drop=y1 where=(y2 ne .)) ;
do n=1 to nobs;
set training(drop=y2) point=n nobs=nobs;
beta=y1 <= y2;
output;
end;
run;
Like this?
proc sql;
create table temp as
select
a.y1 as compare_y1
, b.y2 as compare_y2
, a.y1 <= b.y2 as beta
from (select unique y1 from training where y1 ne .) as a
, (select unique y2 from training where y2 ne .) as b;
quit;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.