BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tbanh
Fluorite | Level 6

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:

 

Screen Shot 2017-02-20 at 9.32.20 PM.png

 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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;

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

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;
mkeintz
PROC Star

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;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1157 views
  • 0 likes
  • 3 in conversation