Closed
Something like this ?
PROC DATASETS LIBRARY=WORK NoList memtype=DATA;
delete have: ; run;
delete want ; run;
QUIT;
data work.have;
input id hospital $ weight;
datalines;
1 A 55
1 B .
1 C 58
1 D .
1 E 59
2 A .
2 C .
2 F 65
2 G 69
3 B .
3 C 70
3 F .
4 C .
4 D .
;
run;
data work.startmissing (keep=id)
work.startnonmissing(keep=id);
set work.have;
by id;
if first.id then do;
if weight = . then output work.startmissing;
else output work.startnonmissing;
end;
run;
PROC SQL noprint;
create table work.have1M as
select * from work.have
where id IN (select id from work.startmissing )
order by id , hospital desc;
create table work.have2NM as
select * from work.have
where id IN (select id from work.startnonmissing)
order by id , hospital ;
QUIT;
PROC EXPAND data=work.have1M
out=work.have1M_expout
METHOD=STEP EXTRAPOLATE;
BY id;
CONVERT weight = weightexp ;
*ID hospital;
run; QUIT;
proc sort data=work.have1M_expout; by id hospital; run;
PROC EXPAND data=work.have2NM
out=work.have2NM_expout
METHOD=STEP EXTRAPOLATE;
BY id;
CONVERT weight = weightexp ;
*ID hospital;
run; QUIT;
/* end of program */
PROC APPEND base=work.want data=work.have1M_expout ;
PROC APPEND base=work.want data=work.have2NM_expout;
PROC SORT data=work.want; by id hospital; run;
/* end of program */
Koen
Something like this ?
PROC DATASETS LIBRARY=WORK NoList memtype=DATA;
delete have: ; run;
delete want ; run;
QUIT;
data work.have;
input id hospital $ weight;
datalines;
1 A 55
1 B .
1 C 58
1 D .
1 E 59
2 A .
2 C .
2 F 65
2 G 69
3 B .
3 C 70
3 F .
4 C .
4 D .
;
run;
data work.startmissing (keep=id)
work.startnonmissing(keep=id);
set work.have;
by id;
if first.id then do;
if weight = . then output work.startmissing;
else output work.startnonmissing;
end;
run;
PROC SQL noprint;
create table work.have1M as
select * from work.have
where id IN (select id from work.startmissing )
order by id , hospital desc;
create table work.have2NM as
select * from work.have
where id IN (select id from work.startnonmissing)
order by id , hospital ;
QUIT;
PROC EXPAND data=work.have1M
out=work.have1M_expout
METHOD=STEP EXTRAPOLATE;
BY id;
CONVERT weight = weightexp ;
*ID hospital;
run; QUIT;
proc sort data=work.have1M_expout; by id hospital; run;
PROC EXPAND data=work.have2NM
out=work.have2NM_expout
METHOD=STEP EXTRAPOLATE;
BY id;
CONVERT weight = weightexp ;
*ID hospital;
run; QUIT;
/* end of program */
PROC APPEND base=work.want data=work.have1M_expout ;
PROC APPEND base=work.want data=work.have2NM_expout;
PROC SORT data=work.want; by id hospital; run;
/* end of program */
Koen
Thanks for marking my response as the solution.
However ...
Keep in mind that this programme is entirely based on a missing value in the first record (for and id) or not.
With PROC TIMEDATA, you can set up mechanisms that are more intelligent.
PROC TIMEDATA is like a data step for time series data. You can look ahead to "future" records.
Entire time series (for a by-group) is taken in memory and at every time point t
, you have access to [ t - i ] AND ALSO to [ t + j ].
Best,
Koen
Is there a reason you are deleting your questions after answered?
They will be marked as solved, but if you delete them the thread becomes fairly useless to everyone else. Please do not delete your questions after they've been answered. It doesn't appear as if you're posting confidential data so that should not be an issue.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.