BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
m1986MM
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

4 REPLIES 4
ballardw
Super User

data want;

     set have;

     where Class_id in (22,23);

run;

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

m1986MM
Obsidian | Level 7

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.

Reeza
Super User

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;

SelsonMuniappen
Calcite | Level 5

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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