<?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: Adding a calculated rows in a table in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782704#M31922</link>
    <description>&lt;P&gt;Add this to the program :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title; footnote;
proc sgplot data=work.want;
  title "Percent across years";
  where type='Percent';
  series x=year y=NY / markers;
  series x=year y=CA / markers;
  format NY CA percent7.2;
  yaxis label='Percent attended';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Sat, 27 Nov 2021 23:18:59 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2021-11-27T23:18:59Z</dc:date>
    <item>
      <title>Adding a calculated rows in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782639#M31909</link>
      <description>&lt;P&gt;I have a hypothetical table as below. All the years (2012 to 2016) have two types of data (number of members attended, and the total number of member in 6 States)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input year type $ NY CA PA FL NC AZ;&lt;BR /&gt;datalines;&lt;BR /&gt;2012 attended 25 33 42 57 68 34&lt;BR /&gt;2012 total 200 250 300 240 300 250&lt;BR /&gt;2013 attended 35 43 52 67 78 64&lt;BR /&gt;2013 total 210 270 330 290 320 280&lt;BR /&gt;2014 attended 45 53 6 77 88 54&lt;BR /&gt;2014 total 230 270 320 260 310 270&lt;BR /&gt;2015 attended 55 63 72 87 98 74&lt;BR /&gt;2015 total 260 300 300 290 360 290&lt;BR /&gt;2016 attended 65 73 82 97 88 64&lt;BR /&gt;2016 total 300 320 330 300 350 320&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to add a row after each pair of rows with same year. These rows will have percentage of total attended in each state.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Nov 2021 04:21:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782639#M31909</guid>
      <dc:creator>Barkat</dc:creator>
      <dc:date>2021-11-27T04:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a calculated rows in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782659#M31910</link>
      <description>&lt;PRE&gt;data have;
input year type $ NY CA ;
datalines;
2012 attended 25 33 42 57 68 34
2012 total 200 250 300 240 300 250
2013 attended 35 43 52 67 78 64
2013 total 210 270 330 290 320 280
2014 attended 45 53 6 77 88 54
2014 total 230 270 320 260 310 270
2015 attended 55 63 72 87 98 74
2015 total 260 300 300 290 360 290
2016 attended 65 73 82 97 88 64
2016 total 300 320 330 300 350 320
;
run;

data want;
 set have;
 by year;
 lag_NY=lag(NY);
 lag_CA=lag(CA);

 output;
 if last.year then do;
   type='Percent';
   NY=lag_NY/NY;
   CA=lag_CA/CA;
   output;
 end;
 drop lag_:;
 run;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Nov 2021 10:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782659#M31910</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-11-27T10:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a calculated rows in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782692#M31915</link>
      <description>AWESOME!!!&lt;BR /&gt;Perfectly worked. I was wondering how can I use array or do loop or macro in this program since I have many columns for State names.</description>
      <pubDate>Sat, 27 Nov 2021 18:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782692#M31915</guid>
      <dc:creator>Barkat</dc:creator>
      <dc:date>2021-11-27T18:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a calculated rows in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782698#M31919</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=i j);
 set have;
 by year;
 array    state{2}     NY     CA;
 array lagstate{2} lag_NY lag_CA;
 do i=1 to dim(state);
  lagstate(i)=lag(state(i));
 end;
 output;
 if last.year then do;
   type='Percent';
   do j=1 to dim(state); 
    state(j)=lagstate(j)/state(j);
   end;
   output;
 end;
 drop lag_:;
 run;
 /* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Add more states as required!&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 27 Nov 2021 21:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782698#M31919</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-11-27T21:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a calculated rows in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782700#M31920</link>
      <description>Excellent!</description>
      <pubDate>Sat, 27 Nov 2021 21:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782700#M31920</guid>
      <dc:creator>Barkat</dc:creator>
      <dc:date>2021-11-27T21:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a calculated rows in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782701#M31921</link>
      <description>I wanted to accept two replies as solution. But I couldn't seem to find they way to do that. I would like to ask a follow up question.&lt;BR /&gt;What would be the SAS program to create a line chart of the percent of the States where the X-axis will have Year and Y-axis will have percent.</description>
      <pubDate>Sat, 27 Nov 2021 22:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782701#M31921</guid>
      <dc:creator>Barkat</dc:creator>
      <dc:date>2021-11-27T22:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a calculated rows in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782704#M31922</link>
      <description>&lt;P&gt;Add this to the program :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title; footnote;
proc sgplot data=work.want;
  title "Percent across years";
  where type='Percent';
  series x=year y=NY / markers;
  series x=year y=CA / markers;
  format NY CA percent7.2;
  yaxis label='Percent attended';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 27 Nov 2021 23:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782704#M31922</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-11-27T23:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a calculated rows in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782706#M31923</link>
      <description>Wonderful!!! Thanks so much!!!</description>
      <pubDate>Sat, 27 Nov 2021 23:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-calculated-rows-in-a-table/m-p/782706#M31923</guid>
      <dc:creator>Barkat</dc:creator>
      <dc:date>2021-11-27T23:46:06Z</dc:date>
    </item>
  </channel>
</rss>

