<?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: Subtracting series of variables in one observation from another observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594480#M170796</link>
    <description>I want 6099’s total to be subtracted from 199’s and 101’s total, ag1 from ag1, ag2 from ag2...</description>
    <pubDate>Mon, 07 Oct 2019 15:25:12 GMT</pubDate>
    <dc:creator>Shirin</dc:creator>
    <dc:date>2019-10-07T15:25:12Z</dc:date>
    <item>
      <title>Subtracting series of variables in one observation from another observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594459#M170785</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like some help in subtracting multiple variables in an observation from another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;GEO&amp;nbsp;&amp;nbsp; YEAR&amp;nbsp;&amp;nbsp;&amp;nbsp;SEX&amp;nbsp;&amp;nbsp; Total&amp;nbsp;&amp;nbsp; AG_1&amp;nbsp; ....... AG_100&lt;/P&gt;
&lt;P&gt;0199&amp;nbsp;&amp;nbsp; 2015&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3543&amp;nbsp;&amp;nbsp;&amp;nbsp; 32 ..............564&lt;/P&gt;
&lt;P&gt;0101&amp;nbsp;&amp;nbsp; 2015&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9764&amp;nbsp;&amp;nbsp;&amp;nbsp; 42...............454&lt;/P&gt;
&lt;P&gt;6099&amp;nbsp;&amp;nbsp; 2015&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1356&amp;nbsp;&amp;nbsp;&amp;nbsp; 87...............457&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0199&amp;nbsp;&amp;nbsp; 2016&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9878&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;77 ..............564&lt;/P&gt;
&lt;P&gt;0101&amp;nbsp;&amp;nbsp; 2016&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6565&amp;nbsp;&amp;nbsp;&amp;nbsp; 65...............454&lt;/P&gt;
&lt;P&gt;6099&amp;nbsp;&amp;nbsp; 2016&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1111&amp;nbsp;&amp;nbsp;&amp;nbsp; 22...............457&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0199&amp;nbsp;&amp;nbsp; 2017&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7865&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;11 ..............564&lt;/P&gt;
&lt;P&gt;0101&amp;nbsp;&amp;nbsp; 2017&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2343&amp;nbsp;&amp;nbsp;&amp;nbsp; 22...............454&lt;/P&gt;
&lt;P&gt;6099&amp;nbsp;&amp;nbsp; 2017&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5376&amp;nbsp;&amp;nbsp;&amp;nbsp; 83...............457&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each year and each sex, I would like to subtract the Total and AG_1 to AG_100 variables from the GEO 0199 and 0101.&lt;/P&gt;
&lt;P&gt;I would also like to set all 6099 Total and AG_1...AG_100 variables to 0 after.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 13:18:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594459#M170785</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2019-10-07T13:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting series of variables in one observation from another observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594460#M170786</link>
      <description>&lt;P&gt;I'm not sure this is what youre asking, but perhaps something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input GEO YEAR SEX Total AG_1 AG_2 AG_3;
datalines;
0199 2015 1 3543 32 564 564
0101 2015 1 9764 42 454 454
6099 2015 1 1356 87 457 457
0199 2016 2 9878 77 564 564
0101 2016 2 6565 65 454 454
6099 2016 2 1111 22 457 457
0199 2017 3 7865 11 564 564
0101 2017 3 2343 22 454 454
6099 2017 3 5376 83 457 457
;

data want;
    set have;
    array _ Total--AG_3;
    if GEO in ('0199', '0101') then Total=Total-sum(of AG:);
    else if GEO='6099' then call stdize('replace','mult=',0, of _[*]);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;geo  year  sex  Total  ag_1  ag_2  ag_3
199  2015  1    2383   32    564   564
101  2015  1    8814   42    454   454
6099 2015  1    0      0     0     0
199  2016  2    8673   77    564   564
101  2016  2    5592   65    454   454
6099 2016  2    0      0     0     0
199  2017  3    6726   11    564   564
101  2017  3    1413   22    454   454
6099 2017  3    0      0     0     0&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Oct 2019 13:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594460#M170786</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-07T13:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting series of variables in one observation from another observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594479#M170795</link>
      <description>Thanks Draycut, close but not quite.... &lt;BR /&gt;I want the third row to be subtracted from the first row and the second row.... and the same for rows 4,5,6 and rows 7,8,9.&lt;BR /&gt;And yes, I want rows 3,6,9 to be all zeros like you have.</description>
      <pubDate>Mon, 07 Oct 2019 15:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594479#M170795</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2019-10-07T15:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting series of variables in one observation from another observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594480#M170796</link>
      <description>I want 6099’s total to be subtracted from 199’s and 101’s total, ag1 from ag1, ag2 from ag2...</description>
      <pubDate>Mon, 07 Oct 2019 15:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594480#M170796</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2019-10-07T15:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting series of variables in one observation from another observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594484#M170799</link>
      <description>&lt;P&gt;So you want to take the rows where GEO=6999 and MERGE them with the original data based on YEAR and SEX values?&lt;/P&gt;
&lt;P&gt;Then subtract the values from the GEO=6999 variables from every row?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be best to stick them into a separate ARRAY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  do until(last.sex);
    set have ;
    by year sex ;
    array original total AG_1-AG_100 ;
    array copy x_total x_ag_1-x_ag_100;
    if geo=6099 then do i=1 to dim(original);
      copy[i]=original[i];
    end;
  end;
  do until(last.sex);
    set have ;
    by year sex ;
    do i=1 to dim(original);
      original[i]=original[i]-copy[i];
    end;
    output;
  end;
  drop i x_: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 15:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594484#M170799</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-07T15:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting series of variables in one observation from another observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594498#M170809</link>
      <description>&lt;P&gt;Thanks Tom, very close I think.&lt;/P&gt;
&lt;P&gt;The Total variable does the exact thing I want it to &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My 100 ish variable starting with AG don't all have number suffix, they go AG_LT_1 .... AG_90PL&lt;/P&gt;
&lt;P&gt;So I changed the "-" to "--" in the array definitions. And now they all get set to 0 somehow.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 16:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594498#M170809</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2019-10-07T16:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting series of variables in one observation from another observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594500#M170811</link>
      <description>&lt;P&gt;You can decide which observations to do the subtraction.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if geo in (6099,199,101) then do i=1 to dim(original);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You should only change the one array. For the COPY array it doesn't matter what names you use. You can even make it larger than it needs to be.&amp;nbsp; You just can't make it smaller than the other array.&amp;nbsp; You cannot use a positional variable list because you are using the ARRAY statement to make NEW variables, they don't exist yet so they don't have any position yet.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array copy x_1 - x_1000 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 17:36:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594500#M170811</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-07T17:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting series of variables in one observation from another observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594523#M170818</link>
      <description>&lt;P&gt;This worked great! Many thanks! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 18:41:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtracting-series-of-variables-in-one-observation-from-another/m-p/594523#M170818</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2019-10-07T18:41:30Z</dc:date>
    </item>
  </channel>
</rss>

