<?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: Inserting a datastep variable value within another variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-datastep-variable-value-within-another-variable-name/m-p/262685#M51345</link>
    <description>&lt;P&gt;VVALUEX function is what you're after. It returns it as a character though, so you need to convert it to numeric, if required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x=vvaluex("x"|Type);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input type $ xA xB xC xD;
x=vvaluex("x"||type);
cards;
A 1 3 0 2
D 0 9 5 3
C 4 2 0 0 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 09 Apr 2016 15:44:52 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-04-09T15:44:52Z</dc:date>
    <item>
      <title>Inserting a datastep variable value within another variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-datastep-variable-value-within-another-variable-name/m-p/262680#M51344</link>
      <description>&lt;P&gt;Hello, I have a simple problem I would apprecieate any help with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose in my dataset I have a variable called TYPE which is A, B, C, or D. Furthermore I have four additional variable xA, xB, xC, xD. What I would like to do is create a new variable x that has the appropriate xA, xB, etc value depending on the TYPE. So if TYPE=A then x=xA, etc. Here is an example table;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="384"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;TYPE&lt;/TD&gt;
&lt;TD width="64"&gt;xA&lt;/TD&gt;
&lt;TD width="64"&gt;xB&lt;/TD&gt;
&lt;TD width="64"&gt;xC&lt;/TD&gt;
&lt;TD width="64"&gt;xD&lt;/TD&gt;
&lt;TD width="64"&gt;x&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;D&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;9&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;C&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried x=x||TYPE and call execute('x=x'||TYPE||';'); but to no avail. I read that you can use some combination of symput and symget.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At worst I can do if TYPE='A' then x=XA, etc. but this is really inefficent code (I have 20 different TYPE letters).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there an elegant solution for this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 09 Apr 2016 15:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-datastep-variable-value-within-another-variable-name/m-p/262680#M51344</guid>
      <dc:creator>spirto</dc:creator>
      <dc:date>2016-04-09T15:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting a datastep variable value within another variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-datastep-variable-value-within-another-variable-name/m-p/262685#M51345</link>
      <description>&lt;P&gt;VVALUEX function is what you're after. It returns it as a character though, so you need to convert it to numeric, if required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x=vvaluex("x"|Type);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input type $ xA xB xC xD;
x=vvaluex("x"||type);
cards;
A 1 3 0 2
D 0 9 5 3
C 4 2 0 0 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Apr 2016 15:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-datastep-variable-value-within-another-variable-name/m-p/262685#M51345</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-09T15:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting a datastep variable value within another variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-datastep-variable-value-within-another-variable-name/m-p/262687#M51346</link>
      <description>&lt;P&gt;This seems like an excellent oppportunity to use arrays. Image to arrays, one temporary with 'A', 'B', etc. The other one with XA, XB, ...&lt;/P&gt;
&lt;P&gt;The loop up the index of TYPE in the first and use that index to assign&amp;nbsp; the value of X to the variable in the second array with the found index.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    array types[4] $ _temporary_  ('A' 'B' 'C' 'D');
    array xs[*] xa xb xc xd;
    type='D';
    x=100;
    do i=1 to dim(types);
      if type=types[i] then xs[i]=x;
    end;
    put _all_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this gets you on your way,&lt;/P&gt;
&lt;P&gt;- Jan&lt;/P&gt;</description>
      <pubDate>Sat, 09 Apr 2016 15:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-datastep-variable-value-within-another-variable-name/m-p/262687#M51346</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-04-09T15:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting a datastep variable value within another variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-a-datastep-variable-value-within-another-variable-name/m-p/262688#M51347</link>
      <description>&lt;P&gt;Oh rats. I did it the other way round. Looks like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt; has the proper solution. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Apr 2016 15:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-a-datastep-variable-value-within-another-variable-name/m-p/262688#M51347</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-04-09T15:47:44Z</dc:date>
    </item>
  </channel>
</rss>

