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

The table i have as below:

 

id        term      course         ind    

2         2016      ENC10        I         

2         2017      ENC10        E        

5        2010       MAT12       E          

5        2012       MAT12      I        

6        2011       STA11        E         

6        2013      STA11         I         

6       2015       STA11         E         

 

Table should be sot like this:

 

proc  sort data = work.a;

by id course term;run;

 

I neen only same id and course sort by term; last 'ind' should be 'E', first or second ind should be 'I'

So the table should be like below

 

id        term      course         ind    

2         2016      ENC10        I         

2         2017      ENC10        E         

6        2011       STA11        E         

6        2013      STA11         I         

6       2015       STA11         E         

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Again, post test data in the form of a datastep, I am not here to type in test data.  As such the logic would be something like:

data have;
set your_data;
by id; if (first.id or lag(first.id)) and ind="I" then k1=1; if last.id and ind="E" then k2=1; run; proc sql; create table WANT as select * from HAVE where ID in (select distinct ID from HAVE where k1 and k2); quit;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Again, post test data in the form of a datastep, I am not here to type in test data.  As such the logic would be something like:

data have;
set your_data;
by id; if (first.id or lag(first.id)) and ind="I" then k1=1; if last.id and ind="E" then k2=1; run; proc sql; create table WANT as select * from HAVE where ID in (select distinct ID from HAVE where k1 and k2); quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1545 views
  • 0 likes
  • 3 in conversation