<?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 Array if do with assignment statement for calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-if-do-with-assignment-statement-for-calculation/m-p/450764#M113545</link>
    <description>&lt;P&gt;I need to calculate the weight differential across doctor visits for 25 unique patients with varying numbers of visits 1-4.&amp;nbsp;&amp;nbsp;I thought transposing the data with an array and&amp;nbsp;an if&amp;nbsp;do statement assignment statements to calculate the weight differential was the way to go (have not done this yet since data not aligning correct).&amp;nbsp; I'm&amp;nbsp;having a problem reading the data i.e.&amp;nbsp;data for patient Y has data from patient X because X only had 3 visits instead of 4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have 2 questions, is this the best approach to calculate the weight differential by patient and what is the treatment for varying visits by patient.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; clinincal2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Patient visit date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; weight gender $ group $;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CARDS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 26mar2007 157 male C&lt;/P&gt;&lt;P&gt;1 2 30jun2007 165 male C&lt;/P&gt;&lt;P&gt;1 3 08aug2007 162 male C&lt;/P&gt;&lt;P&gt;2 1 05jun2008 160 female D&lt;/P&gt;&lt;P&gt;3 1 01jan2007 154 female D&lt;/P&gt;&lt;P&gt;3 2 06feb2007 152 female D&lt;/P&gt;&lt;P&gt;3 3 01jun2007 140 female D&lt;/P&gt;&lt;P&gt;3 4 01aug2007 138 female D&lt;/P&gt;&lt;P&gt;4 1 12mar2007 195 male C&lt;/P&gt;&lt;P&gt;4 2 12jun2007 190 male C&lt;/P&gt;&lt;P&gt;5 1 30apr2007 185 female C&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; clinical3;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; clinical2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; patient;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; visits (&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) V1-V4;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; first.patient &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;visits [i] = Weight;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; last.patient &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;i + &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;retain&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; V1-V4;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Apr 2018 17:51:32 GMT</pubDate>
    <dc:creator>RickyS</dc:creator>
    <dc:date>2018-04-03T17:51:32Z</dc:date>
    <item>
      <title>Array if do with assignment statement for calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-if-do-with-assignment-statement-for-calculation/m-p/450764#M113545</link>
      <description>&lt;P&gt;I need to calculate the weight differential across doctor visits for 25 unique patients with varying numbers of visits 1-4.&amp;nbsp;&amp;nbsp;I thought transposing the data with an array and&amp;nbsp;an if&amp;nbsp;do statement assignment statements to calculate the weight differential was the way to go (have not done this yet since data not aligning correct).&amp;nbsp; I'm&amp;nbsp;having a problem reading the data i.e.&amp;nbsp;data for patient Y has data from patient X because X only had 3 visits instead of 4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have 2 questions, is this the best approach to calculate the weight differential by patient and what is the treatment for varying visits by patient.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; clinincal2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Patient visit date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; weight gender $ group $;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CARDS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 26mar2007 157 male C&lt;/P&gt;&lt;P&gt;1 2 30jun2007 165 male C&lt;/P&gt;&lt;P&gt;1 3 08aug2007 162 male C&lt;/P&gt;&lt;P&gt;2 1 05jun2008 160 female D&lt;/P&gt;&lt;P&gt;3 1 01jan2007 154 female D&lt;/P&gt;&lt;P&gt;3 2 06feb2007 152 female D&lt;/P&gt;&lt;P&gt;3 3 01jun2007 140 female D&lt;/P&gt;&lt;P&gt;3 4 01aug2007 138 female D&lt;/P&gt;&lt;P&gt;4 1 12mar2007 195 male C&lt;/P&gt;&lt;P&gt;4 2 12jun2007 190 male C&lt;/P&gt;&lt;P&gt;5 1 30apr2007 185 female C&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; clinical3;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; clinical2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; patient;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; visits (&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) V1-V4;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; first.patient &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;visits [i] = Weight;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; last.patient &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;i + &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;retain&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; V1-V4;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 17:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-if-do-with-assignment-statement-for-calculation/m-p/450764#M113545</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2018-04-03T17:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: Array if do with assignment statement for calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-if-do-with-assignment-statement-for-calculation/m-p/450793#M113557</link>
      <description>&lt;P&gt;You are turning an easy problem into a difficult one.&amp;nbsp; In the long run, you must Must MUST learn to program with data in its original form (as illustrated in your data set CLINICAL2).&amp;nbsp; Assuming the observations are in the proper order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set clinical2;&lt;/P&gt;
&lt;P&gt;by patient;&lt;/P&gt;
&lt;P&gt;weight_dif = dif(weight);&lt;/P&gt;
&lt;P&gt;if first.patient then weight_dif = .;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This gives you visit-by-visit differences.&amp;nbsp; If you want the difference from the first visit, the tools are similar:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set clinical2;&lt;/P&gt;
&lt;P&gt;by patient;&lt;/P&gt;
&lt;P&gt;if first.patient then baseline_weight = weight;&lt;/P&gt;
&lt;P&gt;retain baseline_weight;&lt;/P&gt;
&lt;P&gt;weight_dif = weight - baseline_weight;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 18:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-if-do-with-assignment-statement-for-calculation/m-p/450793#M113557</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-03T18:43:18Z</dc:date>
    </item>
  </channel>
</rss>

