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

  • Home
  • SEARCH
  • 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 8173989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:20:12+00:00 2026-06-06T22:20:12+00:00

I am trying to detect groups which contain the difference between first age and

  • 0

I am trying to detect groups which contain the difference between first age and second age are greater than 5. For example, if I have the following data, the difference between age in grp=1 is 39 so I want to output that group in a separate data set. Same goes for grp 4.

id  grp age sex
1   1   60  M
2   1   21  M
3   2   30  M
4   2   25  F
5   3   45  F
6   3   30  F
7   3   18  M
8   4   32  M
9   4   18  M
10  4   16  M

My initial idea was to sort them by grp and then get the absolute value between ages using something like if first.grp then do;. But I don’t know how to get the absolute value between first age and second age by group or actually I don’t know how should I start this.

Thanks in advance.

  • 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-06T22:20:13+00:00Added an answer on June 6, 2026 at 10:20 pm

    Here’s one way that I think works.

    data have;
     input id $ grp $ age sex $;
     datalines;
    1   1   60  M
    2   1   21  M
    3   2   30  M
    4   2   25  F
    5   3   45  F
    6   3   30  F
    7   3   18  M
    8   4   32  M
    9   4   18  M
    10  4   16  M
    ;
    
    proc sort data=have ;
     by grp descending age;
    run;
    
    data temp(keep=grp);
     retain old;
     set have;
     by grp descending age;
     if first.grp then old=age;
     if last.grp then do;
      diff=old-age;
      if diff>5 then output ;
     end;
    run;
    
    Data want;
     merge temp(in=a) have(in=b);
     by grp ;
     if a and b;
    run;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to detect if one or more variables contain numbers. I have
I am trying to detect which of the first 3 links is being clicked
I am trying to detect the following expression: $ for example $john or $mike
Trying to detect left click vs right click (without using jQuery!) and I have
I am trying to detect changes in window.location (for example to be notified if
I am trying to detect when an item is checked, and which item is
I have an XML feed (which I don't control) and I am trying to
I am trying to detect if an element has been scrolled out and have
I'm trying to figure out a way to detect groups of files. For instance:
I am trying to detect which web in sharepoint that the user is looking

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.