<?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: Creating a new column with dollars spent on different column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-column-with-dollars-spent-on-different-column/m-p/707250#M217136</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Product WK080116 WK080816 WK081516 Release_week $;
infile datalines dlm=',' dsd;
datalines;
1,50,,,080116
2,,20,,080816
3,,,70,081516
;

data want;
   set have;
   Spending_in_week_0 = input(left(vvaluex(cats('WK', Release_week))), 8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 20 Dec 2020 07:33:20 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-12-20T07:33:20Z</dc:date>
    <item>
      <title>Creating a new column with dollars spent on different column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-column-with-dollars-spent-on-different-column/m-p/707248#M217135</link>
      <description>&lt;P&gt;This is the code I have written so far but it does not work. There are a bunch of columns from different weeks named WK080116 to WK042720, these columns include how many dollars spent on that week. I am looking to create a new column called "spending_in_week_0" which is how many dollars spent on the week of its release. I have a column called Release_week which has the release of the product on that week. Release_week column has variables such as 080116.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I tried to make a code that will input the dollars spent on the release day to a column called Spending_in_week_0. But unfortunately, my code does not work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;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D&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;081516&lt;/TD&gt;&lt;TD&gt;$70&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need results that will create a new column called&amp;nbsp;&lt;SPAN&gt;Spending in Week 0 (release week), that will give me the dollar amount spent on that week.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA Assignment2_new_data_merged3;&lt;BR /&gt;set Assignment2_new_data_merged2;&lt;BR /&gt;array WK WK080116 -- WK042720;&lt;BR /&gt;do over WK;&lt;BR /&gt;if Release_week = substr(vname(WK),3,6) then Spending_in_week_0 = WK;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me to create column Spending_in_week_0 please.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would really appreciate it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Dec 2020 05:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-column-with-dollars-spent-on-different-column/m-p/707248#M217135</guid>
      <dc:creator>KentUmeki94</dc:creator>
      <dc:date>2020-12-20T05:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new column with dollars spent on different column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-column-with-dollars-spent-on-different-column/m-p/707250#M217136</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Product WK080116 WK080816 WK081516 Release_week $;
infile datalines dlm=',' dsd;
datalines;
1,50,,,080116
2,,20,,080816
3,,,70,081516
;

data want;
   set have;
   Spending_in_week_0 = input(left(vvaluex(cats('WK', Release_week))), 8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Dec 2020 07:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-column-with-dollars-spent-on-different-column/m-p/707250#M217136</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-20T07:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new column with dollars spent on different column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-column-with-dollars-spent-on-different-column/m-p/707274#M217140</link>
      <description>&lt;P&gt;Does your real data have only one value per observation like in your example?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so then just take the sum of all of the variables rather than trying to figure out how to access the specific one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Spending_in_week_0 = sum( of wk:);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Dec 2020 18:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-column-with-dollars-spent-on-different-column/m-p/707274#M217140</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-20T18:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new column with dollars spent on different column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-column-with-dollars-spent-on-different-column/m-p/707370#M217175</link>
      <description>&lt;P&gt;The code you have shown seems to create the data you show as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is that you have more than one week's spending in some observations, you just need to output each row:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Assignment2_new_data_merged3;
  set Assignment2_new_data_merged2;
  array WK WK080116 -- WK042720;
  do over WK;
  if Release_week = substr(vname(WK),3,6) then do;
    Spending_in_week_0 = WK;
    output;
    end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Dec 2020 07:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-column-with-dollars-spent-on-different-column/m-p/707370#M217175</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-12-21T07:43:12Z</dc:date>
    </item>
  </channel>
</rss>

