/*
Yes. You can,
But it is very tough task for PROC SQL.
Pick up the right tool (data step) for this kind of task.
*/
data have;
input ID Date :date11. Parameter $;
format Date date11.;
if Parameter='-' then call missing(Parameter);
cards;
1 1-feb-2024 -
1 28-feb-2024 x
1 10-mar-2024 -
1 20-Mar-2024 x
1 31-mar-2024 -
1 01-apr-2024 x
2 1-feb-2024 x
2 28-feb-2024 -
2 10-mar-2024 -
2 20-Mar-2024 -
2 31-mar-2024 x
2 10-apr-2024 x
2 30-apr-2024 -
;
%let month= Apr2024 ;
proc sql;
create table want as
select a.*,Parameter
from
(
select distinct id,date from have
where date<=%sysfunc(intnx(month,"01&month."d,0,e))
group by id
having date=max(date)
) as a
left join
(
select distinct id,Parameter from have
where date<=%sysfunc(intnx(month,"01&month."d,0,e)) and Parameter is not missing
group by id
having date=max(date)
) as b
on a.id=b.id
;
quit;
... View more