<?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: Update the columns using loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561698#M157301</link>
    <description>&lt;P&gt;Ok. Does this work for you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input Id date mmddyy10. Height weight;
format date mmddyy10.;
cards;
11 05/04/2000 156 98
11 04/06/2000 156 94
11 08/08/2001 157 92
23 07/06/2010 187 65
23 12/10/2010 187 68
23 04/05/2011 187 .
23 11/15/2012 187 70
65 10/07/2015 166 84
65 12/12/2016 167 86
;

data Temp;
   Visit_count=0;
   do until (last.Id);
      set Have;
      by Id;
      Visit_count=Visit_count+1;
      output;
   end;
   rename Height=Ht Weight=Wt;
run;

data Want;
input ID Visit_count Ht Wt;
cards;
11 1 . .
11 2 . .
11 3 . .
11 4 . .
11 5 . .
23 1 . .
23 2 . .
23 3 . .
23 4 . .
65 1 . .
65 2 . .
run;

data Want;
   update Want Temp updatemode=missingcheck;
   by ID Visit_count;
   drop Date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 27 May 2019 08:55:09 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-05-27T08:55:09Z</dc:date>
    <item>
      <title>Update the columns using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561690#M157293</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please have a look at the given sample dataset.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
input ID Visit_count Ht Wt;
cards;
11 1 . .
11 2 . .
11 3 . .
11 4 . .
11 5 . .
23 1 . .
23 2 . .
23 3 . .
23 4 . .
65 1 . .
65 2 . .
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input Id date mmddyy10. Height weight;
format date mmddyy10.;
cards;
11 05/04/2000 156 98
11 04/06/2000 156 94
11 08/08/2001 157 92
23 07/06/2010 187 65
23 12/10/2010 187 68
23 04/05/2011 187 .
23 11/15/2012 187 70
65 10/07/2015 166 84
65 12/12/2016 167 86
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have to update the Ht and Wt in&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;want&lt;/EM&gt; &lt;/STRONG&gt;table from &lt;EM&gt;&lt;STRONG&gt;have&lt;/STRONG&gt;.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;But I need to update it through order wise of date. The 1st date noted as VisitCount = 1, 2nd date noted as visitcount =2 and so on...&lt;/P&gt;&lt;P&gt;If the Height/Weight value is null on that Visit it remains null.&lt;/P&gt;&lt;P&gt;I could do it for a small dataset. But I have more than 500 visits for some IDs. I think update using the loop is the only solution.&lt;/P&gt;&lt;P&gt;I expect my OP as&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Visit_count&lt;/TD&gt;&lt;TD&gt;Height&lt;/TD&gt;&lt;TD&gt;weight&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;156&lt;/TD&gt;&lt;TD&gt;98&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;156&lt;/TD&gt;&lt;TD&gt;94&lt;/TD&gt;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gt;&lt;BR /&gt;As well I need to update some other parameters from different tables using the same pattern.&lt;/P&gt;&lt;P&gt;Please help me to solve it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 08:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561690#M157293</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2019-05-27T08:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Update the columns using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561692#M157295</link>
      <description>&lt;P&gt;Are the number of observations for each ID in the two data sets always equal? What if &lt;STRONG&gt;have&amp;nbsp;&lt;/STRONG&gt;contains 4 observations for ID=11?&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 08:43:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561692#M157295</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-27T08:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Update the columns using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561695#M157298</link>
      <description>&lt;P&gt;No that may differ.&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 08:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561695#M157298</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2019-05-27T08:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: Update the columns using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561696#M157299</link>
      <description>&lt;P&gt;Ok.&amp;nbsp;&lt;SPAN&gt;What if&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;have&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN&gt;contains 4 observations for ID=11? Should the fourth observation be added to the data set or should it be left out?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 08:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561696#M157299</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-27T08:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Update the columns using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561697#M157300</link>
      <description>&lt;P&gt;That should be added. Nothing will left out. I edited the above sample. Kindly go through it once again.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 08:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561697#M157300</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2019-05-27T08:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Update the columns using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561698#M157301</link>
      <description>&lt;P&gt;Ok. Does this work for you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input Id date mmddyy10. Height weight;
format date mmddyy10.;
cards;
11 05/04/2000 156 98
11 04/06/2000 156 94
11 08/08/2001 157 92
23 07/06/2010 187 65
23 12/10/2010 187 68
23 04/05/2011 187 .
23 11/15/2012 187 70
65 10/07/2015 166 84
65 12/12/2016 167 86
;

data Temp;
   Visit_count=0;
   do until (last.Id);
      set Have;
      by Id;
      Visit_count=Visit_count+1;
      output;
   end;
   rename Height=Ht Weight=Wt;
run;

data Want;
input ID Visit_count Ht Wt;
cards;
11 1 . .
11 2 . .
11 3 . .
11 4 . .
11 5 . .
23 1 . .
23 2 . .
23 3 . .
23 4 . .
65 1 . .
65 2 . .
run;

data Want;
   update Want Temp updatemode=missingcheck;
   by ID Visit_count;
   drop Date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 May 2019 08:55:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561698#M157301</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-27T08:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Update the columns using loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561737#M157309</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input Id date mmddyy10. Height weight;
format date mmddyy10.;
cards;
11 05/04/2000 156 98
11 04/06/2000 156 94
11 08/08/2001 157 92
23 07/06/2010 187 65
23 12/10/2010 187 68
23 04/05/2011 187 .
23 11/15/2012 187 70
65 10/07/2015 166 84
65 12/12/2016 167 86
;


data Want;
input ID Visit_count Ht Wt;
cards;
11 1 . .
11 2 . .
11 3 . .
11 4 . .
11 5 . .
23 1 . .
23 2 . .
23 3 . .
23 4 . .
65 1 . .
65 2 . .
;
run;
data want;
ina=0;inb=0;
 merge want(in=ina drop=ht wt) have(in=inb drop=date);
 by id;
 if inb=0 then call missing(height,weight);
 if ina;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 May 2019 12:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-the-columns-using-loop/m-p/561737#M157309</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-05-27T12:44:33Z</dc:date>
    </item>
  </channel>
</rss>

