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!

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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