<?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: Use a variable's value as part of another variable's name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/500073#M133115</link>
    <description>&lt;P&gt;Like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;, but specifying explicit array bounds:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array services{2010:2018} service2010-service2018;
num_use_post_death = 0;
do year = death_year+2 to hbound(services);
    num_use_post_death + services{year};
    end;
drop year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 29 Sep 2018 05:01:00 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2018-09-29T05:01:00Z</dc:date>
    <item>
      <title>Use a variable's value as part of another variable's name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/499791#M133031</link>
      <description>&lt;P&gt;I've a dataset with a variable death_year for year of death (2017 or before), and a bunch service use year variables (1 or 0 as yes or no) between 2010 and 2018 (service2010, service2011, service2012, .... service2018). I want to identify # of service use two years after death year to validate the value of death year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;num_use_post_death=sum(of serviceXXXX - service2017);&lt;BR /&gt;where XXXX is the individual person's value of death_year +2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 07:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/499791#M133031</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2018-09-28T07:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Use a variable's value as part of another variable's name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/499797#M133035</link>
      <description>&lt;P&gt;Please post example data (in a data step with datalines), and what you expect out of it.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 07:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/499797#M133035</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-28T07:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Use a variable's value as part of another variable's name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/499800#M133037</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be easier to answer if you post have and want datasets in the form of datasteps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array services(*) service2010-service2018;

    startindex=death_year-2009;
    stopindex=dim(services);

    do i=startindex to stopindex;
        num_use_post_death=sum(num_use_post_death,services(i));
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 07:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/499800#M133037</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-09-28T07:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Use a variable's value as part of another variable's name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/499809#M133039</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array services(2010:2018) service2010-service2018;
  num_use_post_death=0;
  if death_year then do _N_=max(death_year+2,2010) to hbound(services);
    num_use_post_death+services(_N_);
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I put in the MAX function in case you have some that died before 2008.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 08:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/499809#M133039</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-09-28T08:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Use a variable's value as part of another variable's name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/500073#M133115</link>
      <description>&lt;P&gt;Like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;, but specifying explicit array bounds:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array services{2010:2018} service2010-service2018;
num_use_post_death = 0;
do year = death_year+2 to hbound(services);
    num_use_post_death + services{year};
    end;
drop year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Sep 2018 05:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-variable-s-value-as-part-of-another-variable-s-name/m-p/500073#M133115</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-29T05:01:00Z</dc:date>
    </item>
  </channel>
</rss>

