<?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: Shorter way to do variable list 1 = variable list 2 in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697324#M25380</link>
    <description>&lt;P&gt;A simplified example for using the longitudinal dataset in PROC REPORT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input variable $ year value;
datalines;
A 1 111
A 2 222
A 3 333
B 1 444
B 2 555
B 3 666
;

proc report data=have;
column variable year,value;
define variable / group;
define year / across;
define value / "" sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 07 Nov 2020 10:44:50 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-11-07T10:44:50Z</dc:date>
    <item>
      <title>Shorter way to do variable list 1 = variable list 2</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697309#M25375</link>
      <description>&lt;P&gt;I have two arrays, year and yearsum. Yearsum is the sum of values for each year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a new row 'Total' and use the yearsum values as the total values. My code works but it's incredibly inefficient. I am not sure if I can use a DO loop because it will generate 10 rows of 'Total'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last then do;
Variable = 'Total';
year1 = yearsum1;
year2 = yearsum2;
year3 = yearsum3;
year4 = yearsum4;
year5 = yearsum5;
year6 = yearsum6;
year7 = yearsum7;
year8 = yearsum8;
year9 = yearsum9;
year10 = yearsum10;
output;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there a way to write year{i} = yearsum {i} more efficiently?&lt;/P&gt;&lt;P&gt;I did a DO loop for the top portion but I can't apply it to the above code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i = 1 to 10;
yearsum{i} = sum(yearsum{i}, year{i});
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;End result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51484i593CD1F01EA82AB7/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 07:16:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697309#M25375</guid>
      <dc:creator>benjaminchua002</dc:creator>
      <dc:date>2020-11-07T07:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: Shorter way to do variable list 1 = variable list 2</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697315#M25376</link>
      <description>&lt;P&gt;You just need to define ARRAY statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array year year1-year10;
array yearsum yearsum1-yearsum10;

do i = 1 to 10;
    yearsum{i} = sum(yearsum{i}, year{i});
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Nov 2020 07:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697315#M25376</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-11-07T07:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Shorter way to do variable list 1 = variable list 2</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697316#M25377</link>
      <description>&lt;P&gt;A similar result can easily be achieved with PROC REPORT from your untransposed vertical dataset.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 07:57:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697316#M25377</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-07T07:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: Shorter way to do variable list 1 = variable list 2</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697321#M25379</link>
      <description>&lt;P&gt;Yes, you could use arrays, but any time you have a wide data set, with a specific year in the variable names (or any calendar information in the variable names), you have chosen a data arrangement that is more difficult to work with, and probably requires a lot more programming than if you kept the data in a long format, with year as a variable containing values 1 through 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You see, SAS already provides several built-in methods of doing what you are trying to do, they have done the work so you don't have to, if you use a long data set, then you have much less programming. PROC REPORT get this output table easily, without you having to do all the coding of individual years.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 19&lt;/A&gt;. Embrace long data sets. Make your coding simpler.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 10:38:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697321#M25379</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-07T10:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Shorter way to do variable list 1 = variable list 2</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697324#M25380</link>
      <description>&lt;P&gt;A simplified example for using the longitudinal dataset in PROC REPORT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input variable $ year value;
datalines;
A 1 111
A 2 222
A 3 333
B 1 444
B 2 555
B 3 666
;

proc report data=have;
column variable year,value;
define variable / group;
define year / across;
define value / "" sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Nov 2020 10:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Shorter-way-to-do-variable-list-1-variable-list-2/m-p/697324#M25380</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-07T10:44:50Z</dc:date>
    </item>
  </channel>
</rss>

