BookmarkSubscribeRSS Feed
usuario_estudo
Calcite | Level 5

I'd like to write a code that creates column C from A and B. Column C will be, the value of A from the row where B is the smallest value greater or equal to 0.99. If there are repeated values as in the example, the value must be the first of them.

 

A     B             C

1     0.2           4

2     0.05         4

3     0.9           4

4     0.9901     4

5     0.9901     4

6     0.9901     4

7     0.995       4

2 REPLIES 2
Kurt_Bremser
Super User

Use a double do loop:

data want;
_b = 9999999999;
do until (done1);
  set have end=done1;
  if b > .99 and b < _b
  then do;
    _c = a;
    _b = b;
  end;
end;
do until (done2);
  set have end=done2;
  c = _c;
  output;
end;
drop _:;
run;
ghosh
Barite | Level 11
data have;
	input A B;
	cards;
1     0.2    
2     0.05   
3     0.9    
4     0.9901 
5     0.9901 
6     0.9901 
7     0.995 
;

proc sql noprint;
	select a, min(b) into :a trimmed, :b trimmed 
	  from have 
where b ge 0.99; quit; %put a=&a b=&b; data want; set have; c=&a; run;