I have my data like below:
data abc;
input alt_acc$ acc x;
datalines;
2123 001 1
2234 001 0
2345 001 0
Y123 002 4
Y345 002 7
Y513 002 0
Z123 002 6
L123 003 0
L234 003 1
;
run;
I want output like below:
-------------------------------
alt_acc Acc x
2123 001 1
2234 001 0
Y123 002 4
Y345 002 7
Y513 002 0
L123 003 0
I want the records till my x value is zero for all accounts(acc).
data abc; input alt_acc$ acc x; datalines; 2123 001 1 2234 001 0 2345 001 0 Y123 002 4 Y345 002 7 Y513 002 0 Z123 002 6 L123 003 0 L234 003 1 ; run; data want; set abc; by acc; retain is_zero; if first.acc then is_zero=0; if is_zero=0; if x=0 then is_zero=1; drop is_zero; run;
data abc;
input alt_acc$ acc x;
datalines;
2123 001 1
2234 001 0
2345 001 0
Y123 002 4
Y345 002 7
Y513 002 0
Z123 002 6
L123 003 0
L234 003 1
;
run;
data want;
set abc;
by acc;
retain _x;
if first.acc then _x =.;
if _x = . ;
if x=0 then _x=x;
drop _x;
run;
data abc; input alt_acc$ acc x; datalines; 2123 001 1 2234 001 0 2345 001 0 Y123 002 4 Y345 002 7 Y513 002 0 Z123 002 6 L123 003 0 L234 003 1 ; run; data want; set abc; by acc; retain is_zero; if first.acc then is_zero=0; if is_zero=0; if x=0 then is_zero=1; drop is_zero; run;
If zero occurs in X variable for an account, we need before record also for that account in the output
Looks like a case for the do until loop!
data want2;
do until(last.acc);
set abc;
by acc;
if not zerofound then
output;
if x=0 then
zerofound=1;
end;
drop zerofound;
run;
Y123 002 4
Y345 002 7
Above are not capturing
yes they are. Do proc print of want2 dataset.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.