<?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 prefix array element to create dynamic variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356657#M83640</link>
    <description>&lt;P&gt;Your code assumes you have an array named TOTAL. &amp;nbsp;You can create one, but you would need to identify the variables in it. &amp;nbsp;Since you have but a few, it might be simplest to hard-code the names:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data need;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;set have;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;by id;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array deal_sum{*} FAS:;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array total {*} total_FAS_1990_01 total_FAS_1991_01 total_FAS_1991_02 total_FAS_1991_03 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;total_FAS_1992_01 total_FAS_1992_02 total_FAS_1992_03 total_FAS_1993_01;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;do i = 1 to dim(total);&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;total{i} &amp;nbsp;+ deal_sum{i};&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;end;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your actual data set contains more variables, you can use macro language to construct the set of names. &amp;nbsp;But for 8 variable names, why complicate the program?&lt;/P&gt;</description>
    <pubDate>Sat, 06 May 2017 23:12:04 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-05-06T23:12:04Z</dc:date>
    <item>
      <title>How to prefix array element to create dynamic variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356652#M83635</link>
      <description>&lt;P&gt;Hello SAS Users,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create a dynamic variable by adding prefix into an array element. I have a SAS dataset and i need to create a running total for each variables. However, &amp;nbsp;i keep getting an error related to array ref doesn't exist. I don't want to hard code the variable names as new variable names will be added into the dataset every month.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is the SAS code i'm running&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;input id FAS_1990_01&amp;nbsp;&lt;SPAN&gt;FAS_1991_01&lt;/SPAN&gt;&amp;nbsp;FAS_1991_02 FAS_1991_03 FAS_1992_01&amp;nbsp;&lt;SPAN&gt;FAS_1992_02 FAS_1992_03&amp;nbsp;FAS_1993_01;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;datalines;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 7983 1000 1200 3099&amp;nbsp;&lt;SPAN&gt;7083 1009 1900 7099&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2 9000 1500 1300 4390&amp;nbsp;&lt;SPAN&gt;7983 1080 1280 3199&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;3 3898 3090 1400 4980&amp;nbsp;&lt;SPAN&gt;7973 1050 1260 3299&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;4 4654 2483 1500 3879&amp;nbsp;&lt;SPAN&gt;7953 1080 1400 3899&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data need;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;set have;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;by id;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array deal_sum{*} FAS:;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;do i = 1 to dim(total);&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;total_||deal_suml{i} &amp;nbsp;+ deal_sum{i};&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;end;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2017 21:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356652#M83635</guid>
      <dc:creator>zqkal</dc:creator>
      <dc:date>2017-05-06T21:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to prefix array element to create dynamic variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356654#M83637</link>
      <description>&lt;P&gt;Given your example dataset, what do you want the resulting dataset to look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2017 21:34:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356654#M83637</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-06T21:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to prefix array element to create dynamic variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356657#M83640</link>
      <description>&lt;P&gt;Your code assumes you have an array named TOTAL. &amp;nbsp;You can create one, but you would need to identify the variables in it. &amp;nbsp;Since you have but a few, it might be simplest to hard-code the names:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data need;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;set have;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;by id;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array deal_sum{*} FAS:;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array total {*} total_FAS_1990_01 total_FAS_1991_01 total_FAS_1991_02 total_FAS_1991_03 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;total_FAS_1992_01 total_FAS_1992_02 total_FAS_1992_03 total_FAS_1993_01;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;do i = 1 to dim(total);&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;total{i} &amp;nbsp;+ deal_sum{i};&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;end;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your actual data set contains more variables, you can use macro language to construct the set of names. &amp;nbsp;But for 8 variable names, why complicate the program?&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2017 23:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356657#M83640</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-06T23:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to prefix array element to create dynamic variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356666#M83647</link>
      <description>&lt;P&gt;Can you store your data in a long form instead of wide? This violates the best practice of not having 'data' in your column headers.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its also easier to add rows to a dataset versus adding columns. For the running total, if you have SAS/ETS look at PROC EXPAND.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 May 2017 00:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356666#M83647</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-07T00:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to prefix array element to create dynamic variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356894#M83745</link>
      <description>&lt;P&gt;This will creat the desired output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data need; &lt;BR /&gt;set have; &lt;BR /&gt;by id; &lt;BR /&gt;total_FAS_1990_01 + FAS_1990_01; &lt;BR /&gt;total_FAS_1991_01 + FAS_1991_01; &lt;BR /&gt;total_FAS_1991_02 + FAS_1991_02; &lt;BR /&gt;total_FAS_1991_03 + FAS_1991_03; &lt;BR /&gt;total_FAS_1992_01 + FAS_1992_01; &lt;BR /&gt;total_FAS_1992_02 + FAS_1992_02; &lt;BR /&gt;total_FAS_1992_03 + FAS_1992_03; &lt;BR /&gt;total_FAS_1993_01 + FAS_1993_01; &lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 15:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-prefix-array-element-to-create-dynamic-variable/m-p/356894#M83745</guid>
      <dc:creator>zqkal</dc:creator>
      <dc:date>2017-05-08T15:12:43Z</dc:date>
    </item>
  </channel>
</rss>

