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

Hello All

 

I am working with student data, and want to categorize students on the bases of whether they are enrolled in all English as a Second Language (ESL) courses or not. I have gotten so far as to categorizing their individual courses as ESL or not. Please see the table below, I think it will help:

 

StudentID    Course         ESL_Filter

1234            ESL              Keep

1234            Non-ESL      Keep

1234            ESL              Keep

5678            Non-ESL      Keep

5678            Non-ESL      Keep

5678            Non-ESL      Keep

9012            ESL              Remove

9012            ESL              Remove

9012            ESL              Remove

 

Please notice a few things:

- The goal is to create the ESL_Filter column

- Each student has multiple observations (i.e., they're enrolled in multiple courses)

- I want to assign "Remove" only the students who are enrolled in all ESL courses

 

I have the table sorted on StudentID.

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
proc sql;
create table want as
select *,ifc(count(distinct course)=1 and course='ESL','REMOVE',"KEEP") as ESL_Filter
from have
group by StudentID;
quit; 
StudentID Course ESL_Filter
1234 ESL KEEP
1234 Non-ESL KEEP
1234 ESL KEEP
5678 Non-ESL KEEP
5678 Non-ESL KEEP
5678 Non-ESL KEEP
9012 ESL REMOVE
9012 ESL REMOVE
9012 ESL REMOVE

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

data have;
input (StudentID    Course ) ($);*        ESL_Filter;
cards;
1234            ESL              Keep
1234            Non-ESL      Keep
1234            ESL              Keep
5678            Non-ESL      Keep
5678            Non-ESL      Keep
5678            Non-ESL      Keep
9012            ESL              Remove
9012            ESL              Remove
9012            ESL              Remove
;

proc sql;
create table want as
select *
from have
group by StudentID
having not (count(distinct course)=1 and course='ESL');
quit; 
StudentID Course
1234 ESL
1234 Non-ESL
1234 ESL
5678 Non-ESL
5678 Non-ESL
5678 Non-ESL
novinosrin
Tourmaline | Level 20
proc sql;
create table want as
select *,ifc(count(distinct course)=1 and course='ESL','REMOVE',"KEEP") as ESL_Filter
from have
group by StudentID;
quit; 
StudentID Course ESL_Filter
1234 ESL KEEP
1234 Non-ESL KEEP
1234 ESL KEEP
5678 Non-ESL KEEP
5678 Non-ESL KEEP
5678 Non-ESL KEEP
9012 ESL REMOVE
9012 ESL REMOVE
9012 ESL REMOVE
bourdeax
Fluorite | Level 6
Thank you, this is exactly what I was looking for!
Reeza
Super User
proc sql;
create table want as
select * 
from StudentID
where studentID in (select studentID from have having max(course)=min(course) and min(course) = "ESL");
quit;

Another possible option, 

 

proc sort data=have;
by studentID desc course;
run;

data want;
    set have;
    by studentID desc Course;
    retain flag_delete 0;

     if first.studentID and Course = 'ESL' then flag_delete=1;
     
    if flag_delete = 0;

run;

@bourdeax wrote:

Hello All

 

I am working with student data, and want to categorize students on the bases of whether they are enrolled in all English as a Second Language (ESL) courses or not. I have gotten so far as to categorizing their individual courses as ESL or not. Please see the table below, I think it will help:

 

StudentID    Course         ESL_Filter

1234            ESL              Keep

1234            Non-ESL      Keep

1234            ESL              Keep

5678            Non-ESL      Keep

5678            Non-ESL      Keep

5678            Non-ESL      Keep

9012            ESL              Remove

9012            ESL              Remove

9012            ESL              Remove

 

Please notice a few things:

- The goal is to create the ESL_Filter column

- Each student has multiple observations (i.e., they're enrolled in multiple courses)

- I want to assign "Remove" only the students who are enrolled in all ESL courses

 

I have the table sorted on StudentID.

 

Thanks in advance!


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 539 views
  • 3 likes
  • 3 in conversation