<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Retain flag for new calculation if present in one observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573448#M161898</link>
    <description>Thanks for your solution! It was indeed very close and lead to mine &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Mon, 15 Jul 2019 07:20:19 GMT</pubDate>
    <dc:creator>serena13lee</dc:creator>
    <dc:date>2019-07-15T07:20:19Z</dc:date>
    <item>
      <title>Retain flag for new calculation if present in one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573413#M161884</link>
      <description>&lt;P&gt;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?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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

; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 02:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573413#M161884</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-07-15T02:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Retain flag for new calculation if present in one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573417#M161885</link>
      <description>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.</description>
      <pubDate>Mon, 15 Jul 2019 02:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573417#M161885</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-15T02:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Retain flag for new calculation if present in one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573418#M161886</link>
      <description>&lt;P&gt;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!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 02:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573418#M161886</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-07-15T02:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Retain flag for new calculation if present in one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573424#M161891</link>
      <description>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.</description>
      <pubDate>Mon, 15 Jul 2019 03:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573424#M161891</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-15T03:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Retain flag for new calculation if present in one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573426#M161893</link>
      <description>&lt;P&gt;Not exactly what you want, but close maybe a start?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Jul 2019 04:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573426#M161893</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-07-15T04:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Retain flag for new calculation if present in one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573427#M161894</link>
      <description>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?</description>
      <pubDate>Mon, 15 Jul 2019 04:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573427#M161894</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-07-15T04:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Retain flag for new calculation if present in one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573448#M161898</link>
      <description>Thanks for your solution! It was indeed very close and lead to mine &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 15 Jul 2019 07:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573448#M161898</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-07-15T07:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Retain flag for new calculation if present in one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573449#M161899</link>
      <description>&lt;PRE&gt;data in;&lt;BR /&gt;	input Patient $     adtm $   Value     Unit  $   Type $  avisit $ bflag $;&lt;BR /&gt;	cards;&lt;BR /&gt;A Jan12019 1 m Height baseline Y&lt;BR /&gt;A Jan12019 50 kg Weight baseline Y &lt;BR /&gt;A Jan52019 2 m Height visit1 .&lt;BR /&gt;A Jan52019 55 kg Weight visit1 .&lt;BR /&gt;B Jan12019 1 m Height baseline Y&lt;BR /&gt;B Jan12019 50 kg Weight . .&lt;BR /&gt;B Jan52019 55 kg Weight baseline Y&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc sort data=in;&lt;BR /&gt;	by patient adtm descending Type;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;	set in;&lt;BR /&gt;	by patient adtm descending Type;&lt;BR /&gt;	retain weight_ height_;&lt;BR /&gt;	if first.adtm then do;&lt;BR /&gt;		weight_=.;&lt;BR /&gt;		height_=.;&lt;BR /&gt;	end;&lt;BR /&gt;	if type='Weight' then&lt;BR /&gt;		weight_=Value;&lt;BR /&gt;	else if type='Height' then&lt;BR /&gt;		height_=Value;&lt;BR /&gt;&lt;BR /&gt;	if last.adtm then do;&lt;BR /&gt;		bmi=weight_/height_**2;&lt;BR /&gt;	end;&lt;BR /&gt;	output;&lt;BR /&gt;	if bmi ne . then&lt;BR /&gt;		do;&lt;BR /&gt;			type='BMI';&lt;BR /&gt;			value=bmi;&lt;BR /&gt;			unit='kg/m2';&lt;BR /&gt;			output;&lt;BR /&gt;		end;&lt;BR /&gt;	drop height_ weight_ bmi;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 07:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-flag-for-new-calculation-if-present-in-one-observation/m-p/573449#M161899</guid>
      <dc:creator>serena13lee</dc:creator>
      <dc:date>2019-07-15T07:21:42Z</dc:date>
    </item>
  </channel>
</rss>

