<?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: How to add new columns to dataset each time I run my code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776761#M247082</link>
    <description>Yes, use PROC TRANSPOSE. I would label them as DATE_YYYYMMDD and put the date as a label. Or even convert it to week numbers using the WEEK() function. &lt;BR /&gt;</description>
    <pubDate>Wed, 27 Oct 2021 15:14:21 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-10-27T15:14:21Z</dc:date>
    <item>
      <title>How to add new columns to dataset each time I run my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776735#M247076</link>
      <description>&lt;P&gt;I would like that every time I run the code, the POLICY_VINTAGE dataset would add count (NRB) result from processing as another column called eg Week2 and next week3. Is there any additional feature in SAS for that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="postcell post-layout--right"&gt;
&lt;DIV class="s-prose js-post-body"&gt;
&lt;PRE&gt;PROC SQL;   
   create table POLICY_VINTAGE_WEEKLY as
   select distinct 
   POLICY_VINTAGE
  ,count(NRB) as Week &amp;lt;----- here so that week has a consecutive number, e.g. once week1, then week2
   from PolisyEnd
   where POLIS ="A"
   group by 
   POLICY_VINTAGE

;
Quit;
data POLICY_VINTAGE ;
set _work.POLICY_VINTAGE 
;
run; &lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 27 Oct 2021 13:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776735#M247076</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-10-27T13:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new columns to dataset each time I run my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776740#M247078</link>
      <description>&lt;P&gt;I'm afraid that you will need to provide an example of a data set and what you expect to get for a good answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect to get a different variable name then that is an indication of poor design as everything down stream from this would need to have code rewritten.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have any DATE value involved with this data?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 14:05:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776740#M247078</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-27T14:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new columns to dataset each time I run my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776745#M247079</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*run each week;
PROC SQL;   
   create table POLICY_VINTAGE_WEEKLY as
   select distinct 
   POLICY_VINTAGE
  ,count(NRB) as Count,
  today() as Run_Date format=weeku.
   from PolisyEnd
   where POLIS ="A"
   group by 
   POLICY_VINTAGE

;
Quit;

proc append base=policy_vintage data=policy_vintage_weekly;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Consider instead adding rows and a column to identify each week.&lt;/P&gt;
&lt;P&gt;If you really want a wide structure then take your policy_vintage and transpose it as needed for reports.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;General principal -&amp;gt; It's easier and faster to add rows to tables, than it is columns. It also takes up less space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/401093"&gt;@Gieorgie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I would like that every time I run the code, the POLICY_VINTAGE dataset would add count (NRB) result from processing as another column called eg Week2 and next week3. Is there any additional feature in SAS for that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="postcell post-layout--right"&gt;
&lt;DIV class="s-prose js-post-body"&gt;
&lt;PRE&gt;PROC SQL;   
   create table POLICY_VINTAGE_WEEKLY as
   select distinct 
   POLICY_VINTAGE
  ,count(NRB) as Week &amp;lt;----- here so that week has a consecutive number, e.g. once week1, then week2
   from PolisyEnd
   where POLIS ="A"
   group by 
   POLICY_VINTAGE

;
Quit;
data POLICY_VINTAGE ;
set _work.POLICY_VINTAGE 
;
run; &lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 14:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776745#M247079</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-27T14:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new columns to dataset each time I run my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776759#M247081</link>
      <description>Is there posibility to change columns with date to Row. For example i have first columns with date 2021-01 etc to make like a headers</description>
      <pubDate>Wed, 27 Oct 2021 15:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776759#M247081</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-10-27T15:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new columns to dataset each time I run my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776761#M247082</link>
      <description>Yes, use PROC TRANSPOSE. I would label them as DATE_YYYYMMDD and put the date as a label. Or even convert it to week numbers using the WEEK() function. &lt;BR /&gt;</description>
      <pubDate>Wed, 27 Oct 2021 15:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776761#M247082</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-27T15:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new columns to dataset each time I run my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776890#M247106</link>
      <description>Thanks Reeza, if I understand correctly, when I play this code next week next to Count there will be a new column count. Because now when I play it doesn't get a new column, it's because it's still the same week</description>
      <pubDate>Thu, 28 Oct 2021 06:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/776890#M247106</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-10-28T06:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new columns to dataset each time I run my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/777003#M247141</link>
      <description>Nope, it won't magically add a new column. The process you seem to be doing is one where you will be running this each week and adding it to a master file. &lt;BR /&gt;If you're just running it each week and restating your data, then you need a different approach. In that case, do you have a date column? Or how do you know which data belongs to which week?&lt;BR /&gt;I think you need to explain your use case a bit more.</description>
      <pubDate>Thu, 28 Oct 2021 15:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-columns-to-dataset-each-time-I-run-my-code/m-p/777003#M247141</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-28T15:27:56Z</dc:date>
    </item>
  </channel>
</rss>

