DATA Step, Macro, Functions and more

Help me solve in best way possible without creating extra variables

Reply
N/A
Posts: 0

Help me solve in best way possible without creating extra variables

Hi,

i just need to retain records where for every unique value of var1,
if var2 hold values 'g' & 'b' then should reatin rows with value 'g',
else if it hold only 'g' all the rows, if only 'b' even all the rows should be retianed,
i have enclosed the ouput which would help understand much better.

data a;
input var1 var2 $;
datalines;
1 g
1 g
1 b
1 g
2 b
2 b
3 g
3 g
;
run;

o/p
1 g
1 g
1 g
2 b
2 b
3 g
3 g

Thanks!
Sri..
Super Contributor
Posts: 359

Re: Help me solve in best way possible without creating extra variables

proc sql;

create table two as select a.* from a
where put(var1, 1.)|| var2 in (select put(var1, 1.)|| max(var2) from a group by var1);
quit;
N/A
Posts: 0

Re: Help me solve in best way possible without creating extra variables

Thanks a ton!!
Ask a Question
Discussion stats
  • 2 replies
  • 95 views
  • 0 likes
  • 2 in conversation