BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DBAgFinance
Fluorite | Level 6

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?

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

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.

DBAgFinance
Fluorite | Level 6

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1326 views
  • 1 like
  • 2 in conversation