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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 1419 views
  • 0 likes
  • 3 in conversation