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
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;
You have repeatedly been shown how to post data in a data step, and repeatedly been asked by users to do so.
DO SO NOW.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.