<?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 write a shorter code for variablelist1 = variablelist2 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-a-shorter-code-for-variablelist1-variablelist2/m-p/697583#M213207</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355953"&gt;@benjaminchua002&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need year{i} to equal yearsum{i}. For now, I have it coded as below. It works but it's incredibly inefficient. Is there a shorter way to do this?&amp;nbsp;I have two arrays: year1-year10 and yearsum1-yearsum10. Yearsum is the sum of values in each year (1 to 10).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last then do;&lt;BR /&gt;&lt;BR /&gt;Variable = 'Total';&lt;BR /&gt;&lt;BR /&gt;year1 = yearsum1;
year2 = yearsum2;
year3 = yearsum3;
year4 = yearsum4;
year5 = yearsum5;
year6 = yearsum6;
year7 = yearsum7;
year8 = yearsum8;
year9 = yearsum9;
year10 = yearsum10;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can't use a DO i = 1 to 10 as 'Total' will show up 10 times. I only want one row of 'Total'.&amp;nbsp;&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/51483i2787019E7BA66636/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Restructuring your data in this fashion, to create a wide data set, is rarely needed, and there are easier ways to get the final result with 10 years going across and variable going down the left side with a total row below. PROC REPORT will get you there without the need to code each year separately or rename variables.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Nov 2020 11:51:02 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-11-09T11:51:02Z</dc:date>
    <item>
      <title>How to write a shorter code for variablelist1 = variablelist2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-a-shorter-code-for-variablelist1-variablelist2/m-p/697303#M213079</link>
      <description>&lt;P&gt;I need year{i} to equal yearsum{i}. For now, I have it coded as below. It works but it's incredibly inefficient. Is there a shorter way to do this?&amp;nbsp;I have two arrays: year1-year10 and yearsum1-yearsum10. Yearsum is the sum of values in each year (1 to 10).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last then do;&lt;BR /&gt;&lt;BR /&gt;Variable = 'Total';&lt;BR /&gt;&lt;BR /&gt;year1 = yearsum1;
year2 = yearsum2;
year3 = yearsum3;
year4 = yearsum4;
year5 = yearsum5;
year6 = yearsum6;
year7 = yearsum7;
year8 = yearsum8;
year9 = yearsum9;
year10 = yearsum10;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I can't use a DO i = 1 to 10 as 'Total' will show up 10 times. I only want one row of 'Total'.&amp;nbsp;&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/51483i2787019E7BA66636/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:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-a-shorter-code-for-variablelist1-variablelist2/m-p/697303#M213079</guid>
      <dc:creator>benjaminchua002</dc:creator>
      <dc:date>2020-11-07T07:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a shorter code for variablelist1 = variablelist2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-a-shorter-code-for-variablelist1-variablelist2/m-p/697487#M213155</link>
      <description>&lt;P&gt;Using an array would be even less efficient, and would make the code harder to read.&lt;/P&gt;
&lt;P&gt;Using a rename statement would be the most efficient.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 00:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-a-shorter-code-for-variablelist1-variablelist2/m-p/697487#M213155</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-11-09T00:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a shorter code for variablelist1 = variablelist2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-a-shorter-code-for-variablelist1-variablelist2/m-p/697583#M213207</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355953"&gt;@benjaminchua002&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need year{i} to equal yearsum{i}. For now, I have it coded as below. It works but it's incredibly inefficient. Is there a shorter way to do this?&amp;nbsp;I have two arrays: year1-year10 and yearsum1-yearsum10. Yearsum is the sum of values in each year (1 to 10).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last then do;&lt;BR /&gt;&lt;BR /&gt;Variable = 'Total';&lt;BR /&gt;&lt;BR /&gt;year1 = yearsum1;
year2 = yearsum2;
year3 = yearsum3;
year4 = yearsum4;
year5 = yearsum5;
year6 = yearsum6;
year7 = yearsum7;
year8 = yearsum8;
year9 = yearsum9;
year10 = yearsum10;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can't use a DO i = 1 to 10 as 'Total' will show up 10 times. I only want one row of 'Total'.&amp;nbsp;&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/51483i2787019E7BA66636/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Restructuring your data in this fashion, to create a wide data set, is rarely needed, and there are easier ways to get the final result with 10 years going across and variable going down the left side with a total row below. PROC REPORT will get you there without the need to code each year separately or rename variables.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 11:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-a-shorter-code-for-variablelist1-variablelist2/m-p/697583#M213207</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-09T11:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a shorter code for variablelist1 = variablelist2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-write-a-shorter-code-for-variablelist1-variablelist2/m-p/697618#M213222</link>
      <description>&lt;P&gt;What do you mean by incredibly inefficient?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you would like to use your arrays so that your program is shorter, you can.&amp;nbsp; This decreases the amount of code to write, but would not decrease the execution time, because you're still doing 11 assignment statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last then do;
  Variable= "Total" ;
  do i=1 to dim(year) ;
    year{i}=yearsum{i} ;
  end ;
  output ;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As of others have mentioned, this type of wide dataset often creates the need for clunky code like this.&amp;nbsp; Typically code is easier when data are structured vertically.&amp;nbsp; If you had a variable for Year, and variables for Wages Retirement Medical, then you would create a Total variable as just Total=sum(Wages,Retirement,Medical).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel like I spent the first 5 years of my SAS programming learning how to use arrays, and then spent the second 5 years learning to recognize when my thought to use an array was an indication of a data structure problem.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 14:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-write-a-shorter-code-for-variablelist1-variablelist2/m-p/697618#M213222</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-11-09T14:06:06Z</dc:date>
    </item>
  </channel>
</rss>

