<?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 value of a variable to reference another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-a-variable-to-reference-another-variable/m-p/822490#M324795</link>
    <description>&lt;P&gt;Here is a simple datastep that does the job. Less sophisticated than &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt; 's suggestion but it should provide a good starting point :&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 x George -- Many_more_name;
do i = 1 to dim(x);
    if upcase(vname(x{i})) = upcase(select_person) then do;
        x{i} = 0.8 * x{i};
        leave;
        end;
    end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Jul 2022 03:41:34 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2022-07-11T03:41:34Z</dc:date>
    <item>
      <title>Use value of a variable to reference another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-a-variable-to-reference-another-variable/m-p/822219#M324664</link>
      <description>&lt;P&gt;Hi this appears conceptually to be simple so hopefully it is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large dataset with many variables and many records structured as follows:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data have;
input unique_ID$ George Fred Jane Mary Many_more_name select_person$;
cards;
kpss 0 0.3 1 1 0.6 Fred
ussu 0.7 1 1 0 1 Mary
esop 1 0.2 0 0 0.2 Fred
aoal 0 1 0.1 0.3 1 Jane
;
run;&lt;/PRE&gt;&lt;P&gt;For each record, I wish multiply by 0.8 the value of the variable whose name is stored in "select_person" such that I obtain:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;unique_ID George  Fred	 Jane	Mary	Many_more_name	select_person
kpss	  0	  0.24	 1	1	0.6	        Fred
ussu	  0.7	  1	 1	0	1	        Mary
esop	  1	  0.16	 0	0	0.2	        Fred
aoal	  0	  1	 0.08	0.3	1	        Jane&lt;/PRE&gt;&lt;P&gt;Apologies if this appears elsewhere I posted earlier but could not find my post.&lt;/P&gt;&lt;P&gt;Many thanks in advnce&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 08:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-a-variable-to-reference-another-variable/m-p/822219#M324664</guid>
      <dc:creator>SASsyMartin</dc:creator>
      <dc:date>2022-07-08T08:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of a variable to reference another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-a-variable-to-reference-another-variable/m-p/822222#M324667</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/429201"&gt;@SASsyMartin&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could create an array of the numeric variables, store their names in another array (in uppercase to avoid case mismatches) and then determine the relevant array index by means of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0jfvenvsqk24vn1q2ypospoq9ij.htm" target="_blank" rel="noopener"&gt;WHICHC function&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_:);
set have;
array _a[*] George--Many_more_name;
array _v[999] $32 _temporary_;
if _n_=1 then do _i=1 to dim(_a);
  _v[_i]=upcase(vname(_a[_i]));
end;
_w=whichc(upcase(select_person), of _v[*]);
_a[_w]=round(0.8*_a[_w],1e-10);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Increase the dimension of array &lt;FONT face="courier new,courier"&gt;_v&lt;/FONT&gt; if it needs to accommodate more than 999 variable names. The code above assumes variable names following the standards of &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lesysoptsref/p124dqdk8zoqu3n1r4nsfqu5vx52.htm#p0x48z14jasjk3n1oy357sexxif5" target="_blank" rel="noopener"&gt;VALIDVARNAME=V7&lt;/A&gt;. Depending on the numeric values in array &lt;FONT face="courier new,courier"&gt;_a&lt;/FONT&gt; you may want to use a different rounding unit or maybe not apply the ROUND function at all (at the risk of introducing rounding errors due to numeric representation issues).&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 09:36:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-a-variable-to-reference-another-variable/m-p/822222#M324667</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-07-08T09:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of a variable to reference another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-a-variable-to-reference-another-variable/m-p/822314#M324714</link>
      <description>&lt;P&gt;VVALUEX()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want = input(vvaluex(select_person), best12.)*0.8;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/429201"&gt;@SASsyMartin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi this appears conceptually to be simple so hopefully it is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a large dataset with many variables and many records structured as follows:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data have;
input unique_ID$ George Fred Jane Mary Many_more_name select_person$;
cards;
kpss 0 0.3 1 1 0.6 Fred
ussu 0.7 1 1 0 1 Mary
esop 1 0.2 0 0 0.2 Fred
aoal 0 1 0.1 0.3 1 Jane
;
run;&lt;/PRE&gt;
&lt;P&gt;For each record, I wish multiply by 0.8 the value of the variable whose name is stored in "select_person" such that I obtain:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;unique_ID George  Fred	 Jane	Mary	Many_more_name	select_person
kpss	  0	  0.24	 1	1	0.6	        Fred
ussu	  0.7	  1	 1	0	1	        Mary
esop	  1	  0.16	 0	0	0.2	        Fred
aoal	  0	  1	 0.08	0.3	1	        Jane&lt;/PRE&gt;
&lt;P&gt;Apologies if this appears elsewhere I posted earlier but could not find my post.&lt;/P&gt;
&lt;P&gt;Many thanks in advnce&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 16:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-a-variable-to-reference-another-variable/m-p/822314#M324714</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-08T16:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of a variable to reference another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-a-variable-to-reference-another-variable/m-p/822490#M324795</link>
      <description>&lt;P&gt;Here is a simple datastep that does the job. Less sophisticated than &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt; 's suggestion but it should provide a good starting point :&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 x George -- Many_more_name;
do i = 1 to dim(x);
    if upcase(vname(x{i})) = upcase(select_person) then do;
        x{i} = 0.8 * x{i};
        leave;
        end;
    end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jul 2022 03:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-a-variable-to-reference-another-variable/m-p/822490#M324795</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-07-11T03:41:34Z</dc:date>
    </item>
  </channel>
</rss>

