BookmarkSubscribeRSS Feed
jeka1212
Obsidian | Level 7

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, 

 

y1y2
2828
15.515.5
8.28.2
3.43.4
17.317.3
15.215.2
32.932.9
11.111.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;
4 REPLIES 4
novinosrin
Tourmaline | Level 20

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;
jeka1212
Obsidian | Level 7
Yes indeed this what I wanted . Many thanks novinosrin for your time
ChrisNZ
Tourmaline | Level 20

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;

 

jeka1212
Obsidian | Level 7
Many thanks ChrisNZ. This is correct too

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1408 views
  • 0 likes
  • 3 in conversation