Prev: Need to find a value that can make the equation's value = 0 like Solver in Excel
Next: Need to find a value that can make the equation's value = 0 like Solver in Excel
From: mahender on 10 Jul 2010 20:38 data new; input id transaction $; datalines; 101 x 101 a 101 s 102 w 102 e 103 f 104 f 105 g 105 h 108 q 108 w 108 f ; run; this is the data set and i need 1st 2 transaction from every id for the whole data..using sas or procsql
From: Patrick on 10 Jul 2010 21:55 data want; set new; by id; if first.id then flag=0; flag+1; if flag<=2 then output; drop flag; run;
From: Patrick on 10 Jul 2010 22:01 ...."flag" is not a good variable name in this context, "counter" sounds more appropriate, so: data want; set new; by id; if first.id then counter=0; counter+1; if counter<=2 then output; drop counter; run;
From: data _null_; on 11 Jul 2010 08:35 On Jul 10, 9:01 pm, Patrick <patrick.mat...(a)gmx.ch> wrote: > ..."flag" is not a good variable name in this context, "counter" > sounds more appropriate, so: > > data want; > set new; > by id; > if first.id then counter=0; > counter+1; > if counter<=2 then output; > drop counter; > run; The same but different... data want; do _n_ = 1 by 1 until(last.id); set new; by id; if _n_ le 2 then output; end; run;
From: Patrick on 11 Jul 2010 10:26
....or under the assumption that an ID is never missing: data want; set new; by id; if lag2(id) ne id then output; run; |