BookmarkSubscribeRSS Feed
superbibi
Obsidian | Level 7

Hi friend, I have a data set that some of the participants are missing some of the visit data. I want to make up those missing for later imputation. I can only come up with the method with generating a missing data set for those participants and then stack with the original data set. Could you show me a faster way?

Thanks.

 

data I have

Obsrandomizationvisittacbase_tac
1618001288248824
2618001390888824
3618001497848824
4618002279627962
5618002383187962
6618002488197962
761800321063010630

 

data I want

Obsrandomizationvisittacbase_tac
1618001288248824
2618001390888824
3618001497848824
4618002279627962
5618002383187962
6618002488197962
761800321063010630
76180033 10630
76180034 10630
3 REPLIES 3
PaigeMiller
Diamond | Level 26

Could you explain further ... why does 618003 get two extra rows, and the other IDs do not get additional rows?

--
Paige Miller
superbibi
Obsidian | Level 7

@PaigeMiller. Thank you for the interest. Each ID should have 3 visits. The visit3,4 is missing for ID 618003. Therefore, if I want to impute the missing values for ID 618003, I think I have to generate the missing cells for ID 618003. The rest of the ID have visit2,3,4, without missing. That is why only ID 618003 requires the additional two rows. Is it clear? Please let me know.

Thank you again.

 

r_behata
Barite | Level 11

Is this what you are looking for :

 

data have;
input Obs randomization visit tac base_tac ;
cards;
1 618001 2 22 22
2 618001 3 33 22
3 618001 4 44 33
4 618002 2 44 33
5 618002 3 33 33
6 618002 4 33 33
7 618003 2 33 55
;
run;

Proc SQl;
Create table temp as 
	select distinct randomization 
	from have;
Quit;

data visit;
	do visit=2 to 4;
		output;
	end;
run;

data temp2;
set temp;
	do i=1 to nobs_;
		set visit point=i nobs=nobs_; output;
	end;
run;


proc sort data=have;
	by randomization visit;
run;

data want;
	merge have temp2;
	by randomization visit;
	
	retain base_tac_;

	if first.randomization then base_tac_=base_tac;
		if missing(base_tac) then base_tac=base_tac_;
	obs=_n_;
	drop base_tac_;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 503 views
  • 0 likes
  • 3 in conversation