Help using Base SAS procedures

Finding the observations whose variable's values are the same as a specific observation

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

Finding the observations whose variable's values are the same as a specific observation

Hi everyone,

I want to create a subset from a dataset. Suppose I have a table like below. What I want to do is keeping all those observations with the same value of Class_ID as what student 1111 has. In this case, I want to create a subset of all observations that the values of their class_ID are equal to 22 or 33.

Student_IDClass_IDScore
111122A
111133A
252022A
252044A
514833A
514866A
625155A

I appreciate any suggestion.


Accepted Solutions
Solution
‎02-02-2015 03:17 PM
Super User
Posts: 19,867

Re: Finding the observations whose variable's values are the same as a specific observation

This won't scale to larger data, you need to be more explicit to what your problem is.

proc sql;

create table want as

select *

from have

where class_id in (select class_id from have where student_id = '1111');

quit;

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Finding the observations whose variable's values are the same as a specific observation

data want;

     set have;

     where Class_id in (22,23);

run;

If Class_id is character then use ('22','23')

Contributor
Posts: 65

Re: Finding the observations whose variable's values are the same as a specific observation

Actually the dataset is very large. So I can't easily find all values, like 22 or 33. I'm looking for an algorithm that can find all the values belonging to a certain student_ID, and then keep those observations that have the same value.

Solution
‎02-02-2015 03:17 PM
Super User
Posts: 19,867

Re: Finding the observations whose variable's values are the same as a specific observation

This won't scale to larger data, you need to be more explicit to what your problem is.

proc sql;

create table want as

select *

from have

where class_id in (select class_id from have where student_id = '1111');

quit;

New Contributor
Posts: 3

Re: Finding the observations whose variable's values are the same as a specific observation

Without further detail about what you are trying to do, my best suggestion would be the same as Reeza, assuming that for every case you know which student_id has the values you are looking for.

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 245 views
  • 0 likes
  • 4 in conversation