Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8220951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:43:44+00:00 2026-06-07T13:43:44+00:00

I have a SAS data set, which I have sorted according to my needs.

  • 0

I have a SAS data set, which I have sorted according to my needs. I want to split it into BY groups and, for each group, output each observation until the first occurrence of a particular value in a particular column.

ID      No  C1  Year2   C3  Date (DD/MM/YYYY)
---------------------------------------------------------      
AB123   4   B4  2008E   OC  09/04/2008
AB123   3   B4  2008E   EL  09/04/2008
AB123   2   B4  2008E   ZZ  09/04/2008
AB123   1   B4  2008E   OC  09/04/2008
AB123   0   B4  2008E   ZZ  09/04/2008
AB123   1   B4  2008E   OC  06/02/2008
AB123   0   B4  2008E   ZZ  06/02/2008

This is one BY group: the data set is grouped by ID, C1, Year2 and sorted by ID, C1, Year2, Date(desc), No(desc). Further instances of each of ID, C1 and Year2 could occur anywhere in the data set, but the 3 variables define each BY group.

I want to output all observations per BY group up to and including the first occurrence of ZZ in C3. So above I would want the first 3 observations output (or flagged) and then move on to the next BY group.

Any help would be greatly appreciated. Please let me know if you need any more details of the problem. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:43:45+00:00Added an answer on June 7, 2026 at 1:43 pm

    Here’s one way that should work.

    data have;
    input ID $ No C1 $ Year2 $ C3 $ Date :DDMMYY10.;
    format date DDMMYY10.;
    cards;
    AB123   4   B4  2008E   OC  09/04/2008
    AB123   3   B4  2008E   EL  09/04/2008
    AB123   2   B4  2008E   ZZ  09/04/2008
    AB123   1   B4  2008E   OC  09/04/2008
    AB123   0   B4  2008E   ZZ  09/04/2008
    AB123   1   B4  2008E   OC  06/02/2008
    AB123   0   B4  2008E   ZZ  06/02/2008
    ;
    run;
    
    data want (drop=stopflag);
    set have;
    by id c1 year2;
    retain stopflag;
    if max(first.id,first.c1,first.year2)=1 then stopflag=0;
    if c3='ZZ' and stopflag=0 then do;
        output;
        stopflag=1;
    end;
    if stopflag=0 then output;
    run;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable called var in SAS/IML. I want to know how I
I have a hypothetical set of data with 3 columns that has monthly profit
I'm writing a web app which is used a SaS. Each customer has their
I have an FPGA device with which my code needs to talk. The protocol
I have a data.frame in R which has been constructed off the Example 1-3
I have a data entry form that has remote validation set up to check
In my UIViewController descendant, I have a set of four blocks. Each block is
I have a SAS program that loops through certain sets of data and generates
I want to remove columns/variables from a large SAS dataset, call it 'data'. I
I have a data set similar to this one: DATA zzz; input prop $15.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.