<?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 set of variables from values in a do loop in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/710005#M26751</link>
    <description>&lt;P&gt;Thanks for the clarification! However, there is one small issue that I noticed when I looked at my data. The column names are actually age_1_sum to age_5_sum and so on. How would I add those into the arrays since the variable names don't end with the numbers?&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jan 2021 19:23:13 GMT</pubDate>
    <dc:creator>aalluru</dc:creator>
    <dc:date>2021-01-07T19:23:13Z</dc:date>
    <item>
      <title>Creating a set of variables from values in a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/709984#M26746</link>
      <description>&lt;P&gt;I am trying to create 5 variables each for a bunch of groups.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to do so with a do loop as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data new_data;
	set sasave.scorecard_vars;
	do i = 1 to 5;
		age_i_perc = age_i / sum(of age_1-age_5);
		marks_i_perc = marks_i / sum(of marks_1-marks_5);
............................. and so on
	end;
run;&lt;/PRE&gt;&lt;P&gt;How can I reference the value of i into the variable name so that the variables will be created as age_1_perc, age_2_perc and so on?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 18:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/709984#M26746</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2021-01-07T18:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a set of variables from values in a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/709987#M26747</link>
      <description>&lt;P&gt;Use arrays, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new_data;
set sasave.scorecard_vars;

array age age_1-age_5 ;
array marks marks_1-marks_5 ;
array age_perc  age_perc_1-age_perc_5;
array marks_perc marks_perc_1-marks_perc_5;

	do i = 1 to 5;
		age_perc{i} = age{i} / sum(of age{*});
		marks_perc{i} = marks{i} / sum(of marks{*});
............................. and so on
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jan 2021 18:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/709987#M26747</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-01-07T18:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a set of variables from values in a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/709990#M26748</link>
      <description>&lt;P&gt;The columns age_1 to age_5 and marks_1 to marks_5 already exist in the table. Would I still need to make arrays for them?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 18:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/709990#M26748</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2021-01-07T18:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a set of variables from values in a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/709993#M26749</link>
      <description>&lt;P&gt;Restructuring your data and using PROC FREQ is easier, more dynamic and scales better.&lt;/P&gt;
&lt;P&gt;Your data needs to be in a long format and proc freq can report many different levels of percentages.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Transposing data tutorials:&lt;BR /&gt;Wide to Long:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 18:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/709993#M26749</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-01-07T18:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a set of variables from values in a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/709998#M26750</link>
      <description>&lt;P&gt;Yes, an array simply defines a name equivalence. Referring to age{3} is the same as referring to age_3, for the duration of the data step.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 19:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/709998#M26750</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-01-07T19:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a set of variables from values in a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/710005#M26751</link>
      <description>&lt;P&gt;Thanks for the clarification! However, there is one small issue that I noticed when I looked at my data. The column names are actually age_1_sum to age_5_sum and so on. How would I add those into the arrays since the variable names don't end with the numbers?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 19:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/710005#M26751</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2021-01-07T19:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a set of variables from values in a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/710006#M26752</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355241"&gt;@aalluru&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the clarification! However, there is one small issue that I noticed when I looked at my data. The column names are actually age_1_sum to age_5_sum and so on. How would I add those into the arrays since the variable names don't end with the numbers?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just list the actual variable names in the ARRAY statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you should consider changing your naming convention to place the numeric suffix at the end of the name instead of inserting it in the middle.&amp;nbsp; Then you can use variable lists to make your code shorter and easier to create.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 19:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/710006#M26752</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-07T19:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a set of variables from values in a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/710010#M26753</link>
      <description>&lt;P&gt;Yes that worked!! Yeah I thought of that but these names were autogenerated by a macro that the company uses so I couldn't change the variable names. Thank you so much clearing my doubts!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 19:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/710010#M26753</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2021-01-07T19:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a set of variables from values in a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/710027#M26755</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355241"&gt;@aalluru&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes that worked!! Yeah I thought of that but these names were autogenerated by a macro that the company uses so I couldn't change the variable names. Thank you so much clearing my doubts!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since Proc Means&amp;nbsp; and/or Summary will do sums and using the /autoname feature for the output statement create names like that I really hope someone didn't actually go and write a macro to do such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 20:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-set-of-variables-from-values-in-a-do-loop/m-p/710027#M26755</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-07T20:02:27Z</dc:date>
    </item>
  </channel>
</rss>

