Hello,
I am trying to create a process that would select records from a table until a field is flagged, then skip to the next customer;
OBS FLAG Customer
1 0 11111
2 0 11111
3 1 11111
4 0 11111
5 0 22222
6 0 22222
7 1 22222
8 0 22222
9 0 22222
10 1 33333
11 0 33333
In this sample it would pull observations 1,2,3,5,6,7,and 10. After the flag is equal to 1, I would like it to go to the next customer.
Is there a do loop that would complete this action?
Hello @DBAgFinance,
Try this:
data have;
input FLAG Customer;
cards;
0 11111
0 11111
1 11111
0 11111
0 22222
0 22222
1 22222
0 22222
0 22222
1 33333
0 33333
;
data want;
do until(last.customer);
set have;
by customer;
if not finished then output;
if flag then finished=1;
end;
drop finished;
run;
Actually, this code reads all records, but it stops outputting them after flag=1 has been encountered for the respective customer.
Hello @DBAgFinance,
Try this:
data have;
input FLAG Customer;
cards;
0 11111
0 11111
1 11111
0 11111
0 22222
0 22222
1 22222
0 22222
0 22222
1 33333
0 33333
;
data want;
do until(last.customer);
set have;
by customer;
if not finished then output;
if flag then finished=1;
end;
drop finished;
run;
Actually, this code reads all records, but it stops outputting them after flag=1 has been encountered for the respective customer.
Thank you for the help. I was trying to implement the last. variable in a do loop and could not get it to work.
Very much appreciated!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.