I have a longitudinal dataset in long format below which has 7 subjects with Time coded 1 through 4 and a response WMQPCA for each time point:
I would like to create missing data by creating time points 5 through 12 and having missing data for each other variable for those time points but I'm having some trouble doing so. Here is the code I have created so far:
data long_WMQPCA;
set long_WMQPCA;
by SUBID;
if last.SUBID then do Time = 5;
end;
run;
Obviously this isn't working. Does anybody have any hints? Thank you.
Something as below could do (not tested):
data long_WMQPCA;
set long_WMQPCA;
by SUBID time;
output;
if last.SUBID then
do;
call missing(WMQPCA);
_time=time+1;
do Time = _time to 12;
output;
end;
end;
drop _time;
run;
Something as below could do (not tested):
data long_WMQPCA;
set long_WMQPCA;
by SUBID time;
output;
if last.SUBID then
do;
call missing(WMQPCA);
_time=time+1;
do Time = _time to 12;
output;
end;
end;
drop _time;
run;
This program does slightly more that you asked for. It creates 12 records per subject, with T=1 to 12, but accomodates missing T's of any pattern, not just 5 to 12. It assumes data are sorted by T within subid:
data want;
array present{12} _temporary_ (12*0);
set have;
by subid;
present{t}=1;
if last.subid then do T=1 to dim(present);
if present{t} then set have;
else call missing(wmqpca);
output;
present{t}=0;
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.