This is why it is a good idea to follow the guidance for posting questions which you will see when you post. Provide clear test data (in the form of a datasteps) which show you problem, and full information about what needs to happen plus test output.
Why is there are requirement for SQL?
Your main problem here is that your data is transposed - this means the data goes across the table. SQL is built specifically to work with normalised data, i.e. data going down the table. So, step one will be getting the data into a way that SQL can work with, if you have 3 dates then you could do:
select SUBJECT_ID,DATE1 as DATE from HAVE
union all
select SUBJECT_ID,DATE2 as DATE from HAVE
union all
select SUBJECT_ID,DATE3 as DATE from HAVE
From this, you can put it in a sub-query, then do max on that data:
proc sql;
create table WANT as
select distinct SUBJECT_ID,
DATE
from ( select SUBJECT_ID,DATE1 as DATE from HAVE union all select SUBJECT_ID,DATE2 as DATE from HAVE union all select SUBJECT_ID,DATE3 as DATE from HAVE
)
group by SUBJECT_ID;
quit;
... View more