DATA Step, Macro, Functions and more

How to create Time values past current values?

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

How to create Time values past current values?

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.


Accepted Solutions
Solution
‎02-21-2017 01:11 PM
Respected Advisor
Posts: 3,900

Re: How to create Time values past current values?

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


All Replies
Solution
‎02-21-2017 01:11 PM
Respected Advisor
Posts: 3,900

Re: How to create Time values past current values?

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;
Valued Guide
Posts: 797

Re: How to create Time values past current values?

[ Edited ]

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;

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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