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

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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