DATA Step, Macro, Functions and more

How to skip to next "by group" when processing records in data step?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 81
Accepted Solution

How to skip to next "by group" when processing records in data step?

I'm using "by group" processing for a healthcare claims dataset containing records sorted by member ID and service date to determine eligibility for my analysis dataset.

Once I've determined if a particular member is eligible or ineligible, I output the member ID and an eligibility flag to a dataset and then no longer need to process the rest of the claim records for that member.

How can I skip to the first claim for the next member in the dataset? I've tried RETURN, STOP and LEAVE statements with limited success.


Accepted Solutions
Solution
‎09-04-2014 12:56 PM
Respected Advisor
Posts: 3,799

Re: How to skip to next "by group" when processing records in data step?

This skips (if then delete) additional processing for the by group once ELIG is true.  The ELIG criteria in my example is N eq 2;

proc sort data=sashelp.class out=class;
   by sex;
   run;
proc print;
  
run;
data elig;
   set class;
   by sex;
   if not first.sex and elig then delete;
   retain elig 0;
  
if first.sex then do;
      elig =
0;
     
x = 0;
     
end;
   x +
1;
  
if x eq 2 then do;
      elig =
1;
     
output;
     
end;
  
run;
proc print;
  
run;

  

View solution in original post


All Replies
Respected Advisor
Posts: 3,156

Re: How to skip to next "by group" when processing records in data step?

If you are using 'by group' processing, the simple answer is 'No'. The only way to skip obs in data step is to use point=, but then it is not compatible with 'by group'.

You maybe able to do it using a Hash object, but then you need to read in all of the obs into Hash first, beat the purpose anyway.

Good Luck,

Haikuo

Solution
‎09-04-2014 12:56 PM
Respected Advisor
Posts: 3,799

Re: How to skip to next "by group" when processing records in data step?

This skips (if then delete) additional processing for the by group once ELIG is true.  The ELIG criteria in my example is N eq 2;

proc sort data=sashelp.class out=class;
   by sex;
   run;
proc print;
  
run;
data elig;
   set class;
   by sex;
   if not first.sex and elig then delete;
   retain elig 0;
  
if first.sex then do;
      elig =
0;
     
x = 0;
     
end;
   x +
1;
  
if x eq 2 then do;
      elig =
1;
     
output;
     
end;
  
run;
proc print;
  
run;

  
Super User
Posts: 5,516

Re: How to skip to next "by group" when processing records in data step?

Posted in reply to data_null__

Just a matter of style and possibly readability ... I would replace the last 4 lines of the DATA step with 2 lines:

if x eq 2;

elig = 1;

As always, beauty is in the eye of the beholder.

Frequent Contributor
Posts: 81

Re: How to skip to next "by group" when processing records in data step?

Posted in reply to data_null__

Thank you, this was very helpful!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 738 views
  • 3 likes
  • 4 in conversation