+ Reply to Thread
Results 1 to 4 of 4

Thread: Removing observations from sas file

  1. #1
    Points: 1,586, Level: 22
    Level completed: 86%, Points required for next Level: 14

    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Removing observations from sas file




    Hello-
    I am new here and have a question regarding removing observations from my SAS dataset. My dataset looks something like this:
    Name Exam Result
    John math
    John math 84
    John english
    John english 92
    Jane math 81
    Jack english
    Jack english 74

    I need to remove the observations where the result is blank. Does anyone know the code I would use to do this?
    Thanks very much.

  2. #2
    Dark Knight
    Points: 1,886, Level: 25
    Level completed: 86%, Points required for next Level: 14
    vinux's Avatar
    Posts
    1,880
    Thanks
    45
    Thanked 190 Times in 157 Posts
    use data step and where condition
    where Result ne . ;


    data dataset1;
    set dataset;
    where Result ne . ;
    run;
    In the long run, we're all dead.

  3. #3
    Points: 1,586, Level: 22
    Level completed: 86%, Points required for next Level: 14

    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by vinux View Post
    use data step and where condition




    data dataset1;
    set dataset;
    where Result ne . ;
    run;
    thanks very much. i forget to mention that some names might not have a result but i do need to record them as not having a result. for example, there might be someone in my dataset like sarah in the list below

    Name Exam Result
    John math
    John math 84
    John english
    John english 92
    Jane math 81
    Jack english
    Jack english 74
    sarah english
    sarah english
    sarah math
    sarah math

    I would have to record sarah as having no test result in english and no test result in math, so I couldn't remove her completely. How would i do this?
    Thanks again.

  4. #4
    Ninja say what!?!
    Points: 8,297, Level: 61
    Level completed: 49%, Points required for next Level: 153
    Link's Avatar
    Posts
    1,165
    Thanks
    37
    Thanked 83 Times in 75 Posts

    If you need to mark them as having no result, then you should not remove them. What I would do is:

    data name;
    set name;
    if exam='math' and not(result=.) then math_score=1;
    if exam='english' and not(result=.) then eng_score=1;
    proc sort nodup;
    by name;
    run;

    This will mark every person who does have a math or english score and eliminate the repeated observations for you.

+ Reply to Thread

           




Similar Threads

  1. Removing extraneous data from na.omit
    By treesloth in forum R
    Replies: 2
    Last Post: 03-29-2011, 01:41 PM
  2. Removing insignificant variables
    By constantly in forum Regression Analysis
    Replies: 2
    Last Post: 03-21-2011, 01:49 AM
  3. LM test for removing parameter
    By thedreamshaper in forum R
    Replies: 0
    Last Post: 12-01-2010, 01:33 PM
  4. removing blanks across columns
    By shabani in forum SAS
    Replies: 0
    Last Post: 06-01-2009, 04:08 PM
  5. removing a comma from a variable
    By randio23 in forum R
    Replies: 1
    Last Post: 10-25-2006, 08:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats