<?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: Do Loop Deleting All But Last Entry in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Deleting-All-But-Last-Entry/m-p/634678#M188393</link>
    <description>&lt;P&gt;You always create the same table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table a_bal as select&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so you&amp;nbsp;&lt;EM&gt;overwrite&lt;/EM&gt; the result in every iteration of the macro do loop.&lt;/P&gt;
&lt;P&gt;You seem to have a data design problem (wide dataset structure), which is solved best by using proc transpose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=cashflows out=cashflows_long;
by account_no;
var a_balance39-a_balance134;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then join over account_no.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Mar 2020 10:29:48 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-03-25T10:29:48Z</dc:date>
    <item>
      <title>Do Loop Deleting All But Last Entry</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Deleting-All-But-Last-Entry/m-p/634676#M188391</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying to run a do loop for a proc sql statement using the below code&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;%macro create_tables(start,end);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;%do i = &amp;amp;start. %to &amp;amp;end.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;proc sql;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;create table a_bal as select&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;a.*,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;b.a_balance%sysevalf(&amp;amp;i.)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;from accounts a&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;left join cashflows b&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;on a.account_no = b.account_no;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;quit;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;%end;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;%mend;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;%create_tables(39,134);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;But the table output only contains the first column and the last iteration of the loop i.e. a_balance134&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Any idea how to get this table to have all the a_balance fields from 39-134?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 10:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Deleting-All-But-Last-Entry/m-p/634676#M188391</guid>
      <dc:creator>jbk96</dc:creator>
      <dc:date>2020-03-25T10:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop Deleting All But Last Entry</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Deleting-All-But-Last-Entry/m-p/634678#M188393</link>
      <description>&lt;P&gt;You always create the same table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table a_bal as select&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so you&amp;nbsp;&lt;EM&gt;overwrite&lt;/EM&gt; the result in every iteration of the macro do loop.&lt;/P&gt;
&lt;P&gt;You seem to have a data design problem (wide dataset structure), which is solved best by using proc transpose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=cashflows out=cashflows_long;
by account_no;
var a_balance39-a_balance134;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then join over account_no.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 10:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Deleting-All-But-Last-Entry/m-p/634678#M188393</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-25T10:29:48Z</dc:date>
    </item>
  </channel>
</rss>

