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 7785139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:12:28+00:00 2026-06-01T20:12:28+00:00

I am trying to make some existing values to missing values (not deleting them).

  • 0

I am trying to make some existing values to missing values (not deleting them).
Here is the basic structure of my data set.

I want to treat AGE and GENDER as missing whenever A is less than B. For example, when A=1 and B=3, I want to treat values of AGE and GENDER on the last two rows as missing (as shown on the data sets).

In my data both A and B go from 1 to 4 and have every combination of them.

Asterisks mean I have more data between them. Thanks in advance!

BEFORE
    ID A B AGE GENDER
    --------------
    1  1 1 35  M
    *  * * *   *
    *  * * *   *
    5  1 2 23  F
    5  1 2 21  M
    6  1 2 42  F
    6  1 2 43  M
    *  * * *   *
    *  * * *   *
    20 1 3 43  F
    20 1 3 39  M
    20 1 3 23  M
    21 1 3 32  F
    21 1 3 39  M
    21 1 3 23  F
    *  * * *   *
    *  * * *   *
    55 2 4 32  M
    55 2 4 12  M
    55 2 4 31  F
    55 2 4 43  M
    *  * * *   *
    *  * * *   *

AFTER    
     ID A B AGE GENDER
     --------------
     1  1 1 35  M
     *  * * *   *
     *  * * *   *
     5  1 2 23  F
     5  1 2 .   .
     6  1 2 42  F
     6  1 2 .   .
     *  * * *   *
     *  * * *   *
     20 1 3 43  F
     20 1 3 .   .
     20 1 3 .   .
     21 1 3 32  F
     21 1 3 .   .
     21 1 3 .   .
     *  * * *   *
     *  * * *   *
     55 2 4 32  M
     55 2 4 12  M
     55 2 4 .   .
     55 2 4 .   . 
     *  * * *   *
     *  * * *   *
  • 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-01T20:12:28+00:00Added an answer on June 1, 2026 at 8:12 pm

    How about now?

    data temp;
      retain idcount 0;
      set olddata;
    
      ** Create an observation counter for each id **;   
      prev_id = lag(id);
    
      if id ^= prev_id then idcount = 0;
      idcount = idcount + 1;
    
    run;
    
    
    ** Sort the obs by ID in reverse order **; 
    proc sort data=temp; 
        by id descending idcount;
    run;
    
    data temp2;
        retain misscount 0;
        set temp;
        by id descending idcount;
    
        ** Keep the previous age and gender **;
        old_age = age;
        old_gender = gender;
    
        ** Count the number that should be missing **;
        if a < b then nummiss = b - a;
        else nummiss = 0;
    
        ** Set a counter of obs that we will set to missing **;   
        if first.id then misscount = 0;
    
        ** Set the appropriate number of rows to missing and update the counter **;
        if misscount < nummiss then do;
           misscount = misscount + 1;
           call missing(age, gender);
        end;
    run;
    
    proc sort data=temp2 out=temp3(drop=misscount nummiss idcount prev_id);
    by id idcount;
    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 make some game, I'm not going to explain what is
i'm trying to make a program that inserts data into specific places in existing
I'm trying to make some existing JS backwards compatible. I need to override a
I'm trying to make some text bold using HTML, but I'm struggling to get
I'm trying to make some social share buttons at my site, but the urls
I'm trying to make some communication for my PIC devices and I use UDP
I'm trying to make some kind of top for some game stadistics Table it's
I'm trying to make some utils for using with sqlite databases. For that I
I'm trying to make some sort of delay in the view controllers changing. I
I am trying to make some SPARQL queries using vc-db-1.rdf and q1.rq from ARQ

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.