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

Hi, I am calculating BMI from a patient's Height and Weight per patient per date. For each BMI calculation I would like to keep Patient, VisitDate, Visit, and bflag information. There is a typo for patient B on Jan12019 where weight is not marked with the same Visit and bflag info that Height is. I would like for the BMI to have that info. Is there a way I can keep the visit and bflag? 

 

data in;
input Patient $     VisitDate $   Value     Unit  $   Type $  Visit $ bflag $;
cards;
A Jan12019 1 m Height baseline Y
A Jan12019 50 kg Weight baseline Y 
A Jan52019 2 m Height visit1 .
A Jan52019 55 kg Weight visit1 .
B Jan12019 1 m Height baseline Y
B Jan12019 50 kg Weight . .
B Jan52019 55 kg Weight baseline Y
;

proc sort data=in;
by patient VisitDate;
run;

data have;
set in;
by patient VisitDate;
retain height_;
if first.VisitDate then height_=.;
if type='Height' then height_=Value;
if last.VisitDate then bmi=value/height_**2;
output;
if bmi ne . then do;
type='BMI';
value=bmi;
unit='kg/m2';
output;
end;
drop height_ bmi;
run;

data want;
input Patient $     VisitDate $   Value     Unit  $   Type $  Visit $ bflag $;
cards;
A Jan12019 1 m Height baseline Y	
A Jan12019 50 kg Weight baseline Y	
A Jan12019 50 kg/m2 BMI baseline Y	
A Jan52019 2 m Height visit1 .	
A Jan52019 55 kg Weight visit1 .	
A Jan52019 13.75 kg/m2 BMI visit1 .		
B Jan12019 1 m Height baseline Y	
B Jan12019 50 kg Weight . .		
B Jan12019 50 kg/m2 BMI baseline Y		
B Jan52019 55 kg Weight baseline Y

; 

 

1 ACCEPTED SOLUTION

Accepted Solutions
serena13lee
Quartz | Level 8
data in;
input Patient $ adtm $ Value Unit $ Type $ avisit $ bflag $;
cards;
A Jan12019 1 m Height baseline Y
A Jan12019 50 kg Weight baseline Y
A Jan52019 2 m Height visit1 .
A Jan52019 55 kg Weight visit1 .
B Jan12019 1 m Height baseline Y
B Jan12019 50 kg Weight . .
B Jan52019 55 kg Weight baseline Y
;

proc sort data=in;
by patient adtm descending Type;
run;

data want;
set in;
by patient adtm descending Type;
retain weight_ height_;
if first.adtm then do;
weight_=.;
height_=.;
end;
if type='Weight' then
weight_=Value;
else if type='Height' then
height_=Value;

if last.adtm then do;
bmi=weight_/height_**2;
end;
output;
if bmi ne . then
do;
type='BMI';
value=bmi;
unit='kg/m2';
output;
end;
drop height_ weight_ bmi;
run;

 

View solution in original post

7 REPLIES 7
Reeza
Super User
Is this a one off typo or a systemic that you need to correct for other records as well? You handle the two types of cases differently.
serena13lee
Quartz | Level 8

Hi Reeza, I believe this is a systemic issue since I have seen other patients with this issue. Please let me know if you have any further questions. Thanks!

Reeza
Super User
If it's a systemic issue, it would be best if you posted a few examples that illustrate the range you're trying to deal with, ie one that has height missing instead of weight or multiple missing. You should also fix those dates but that's something we can help you with once you post your new data.
serena13lee
Quartz | Level 8
Hi Reeza, thanks for mentioning that. So I took a look and it appears that all of the range of issues are the exact same as the situation with B. I.e. there are only situations where by patient, by visitDate that Height has visit and blflag and Weight does not. Thanks! As for date, is there a preferred format?
heffo
Pyrite | Level 9

Not exactly what you want, but close maybe a start? 

data in;
	input Patient $     VisitDate $   Value     Unit  $   Type $  Visit $ bflag $;
	cards;
A Jan12019 1 m Height baseline Y
A Jan12019 50 kg Weight baseline Y 
A Jan52019 2 m Height visit1 .
A Jan52019 55 kg Weight visit1 .
B Jan12019 1 m Height baseline Y
B Jan12019 50 kg Weight . .
B Jan52019 55 kg Weight baseline Y
;

proc sort data=in;
	by patient descending  VisitDate;
run;

data want;
	set in;
	by patient descending VisitDate;
	retain height_ height_;

	if first.VisitDate then do;
		height_=.;
		weight_=.;
	end;
	if type='Height' then
		height_=Value;
	else if type='Weight' then
		weight_=Value;

	if last.VisitDate then do;
		if weight_ = . then weight_ = lag(value);
		if Visit = . then Visit = lag(Visit);
		if bflag = . then bflag = lag(bflag);
		bmi=weight_/height_**2;
	end;
	output;

	if bmi ne . then
		do;
			type='BMI';
			value=bmi;
			unit='kg/m2';
			output;
		end;

	drop height_ weight_ bmi;
run;
proc sort data=want;
	by patient VisitDate;
run;
serena13lee
Quartz | Level 8
Thanks for your solution! It was indeed very close and lead to mine 🙂
serena13lee
Quartz | Level 8
data in;
input Patient $ adtm $ Value Unit $ Type $ avisit $ bflag $;
cards;
A Jan12019 1 m Height baseline Y
A Jan12019 50 kg Weight baseline Y
A Jan52019 2 m Height visit1 .
A Jan52019 55 kg Weight visit1 .
B Jan12019 1 m Height baseline Y
B Jan12019 50 kg Weight . .
B Jan52019 55 kg Weight baseline Y
;

proc sort data=in;
by patient adtm descending Type;
run;

data want;
set in;
by patient adtm descending Type;
retain weight_ height_;
if first.adtm then do;
weight_=.;
height_=.;
end;
if type='Weight' then
weight_=Value;
else if type='Height' then
height_=Value;

if last.adtm then do;
bmi=weight_/height_**2;
end;
output;
if bmi ne . then
do;
type='BMI';
value=bmi;
unit='kg/m2';
output;
end;
drop height_ weight_ bmi;
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
  • 7 replies
  • 854 views
  • 0 likes
  • 3 in conversation