<?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: addressing a variable by using another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72293#M15591</link>
    <description>You have this problem because you are violating an old programming truism: information belongs in variable &lt;B&gt;values&lt;/B&gt;, not in variable &lt;B&gt;names&lt;/B&gt;.&lt;BR /&gt;
&lt;BR /&gt;
The eliminate this, transpose the data set (proc transpose with the name option will do this easily) so your new structure has two fields, like this:&lt;BR /&gt;
&lt;BR /&gt;
Day  Value&lt;BR /&gt;
1       1234&lt;BR /&gt;
2        5678&lt;BR /&gt;
3        whatever&lt;BR /&gt;
&lt;BR /&gt;
Your problem has just gone away.  You can find the day(s) you want with a subsetting if or a where statement or data set option.  The where can be used in a proc step as well, saving preproceesing.&lt;BR /&gt;
&lt;BR /&gt;
Cheers, &lt;BR /&gt;
&lt;BR /&gt;
Jonathan&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; hello,&lt;BR /&gt;
&amp;gt; i have the following problem: For each observation in&lt;BR /&gt;
&amp;gt; my dataset i have hundreds of columns. They are&lt;BR /&gt;
&amp;gt; named: day_1 day_2 day_3 day_4 day_5.....&lt;BR /&gt;
&amp;gt; Then I have a variable that contains a number, let's&lt;BR /&gt;
&amp;gt; say n=4.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Now I want to create another variable, let's say&lt;BR /&gt;
&amp;gt; 'result', that is equal to day_n.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; In my example it should be: result = day_4&lt;BR /&gt;
&amp;gt; But n is not always 4. So I need a small programme&lt;BR /&gt;
&amp;gt; that helps me to solve that problem.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Thanks in advance for your help.&lt;BR /&gt;
&amp;gt; matt</description>
    <pubDate>Tue, 30 Mar 2010 16:34:02 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-03-30T16:34:02Z</dc:date>
    <item>
      <title>addressing a variable by using another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72287#M15585</link>
      <description>hello,&lt;BR /&gt;
i have the following problem: For each observation in my dataset i have hundreds of columns. They are named: day_1 day_2 day_3 day_4 day_5.....&lt;BR /&gt;
Then I have a variable that contains a number, let's say n=4.&lt;BR /&gt;
&lt;BR /&gt;
Now I want to create another variable, let's say 'result', that is equal to day_n.&lt;BR /&gt;
&lt;BR /&gt;
In my example it should be: result = day_4&lt;BR /&gt;
But n is not always 4. So I need a small programme that helps me to solve that problem.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance for your help.&lt;BR /&gt;
matt</description>
      <pubDate>Mon, 29 Mar 2010 22:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72287#M15585</guid>
      <dc:creator>mattb</dc:creator>
      <dc:date>2010-03-29T22:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: addressing a variable by using another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72288#M15586</link>
      <description>Assign a new SAS CHARACTER variable and use the one of the CAT (concatenate) related functions in a DATA step.  Or look at using the VVALUE or VVALUEX function if you are going to assign a value based on value(s) of other variables in the same observation.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 29 Mar 2010 22:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72288#M15586</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-03-29T22:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: addressing a variable by using another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72289#M15587</link>
      <description>Thanks for your prompt answer. But I cannot see how these functions would help me with my problem.&lt;BR /&gt;
&lt;BR /&gt;
I try to explain it in another way:&lt;BR /&gt;
&lt;BR /&gt;
price_1 = 10;&lt;BR /&gt;
number = 1;&lt;BR /&gt;
result = ( value of price_number ) = 10&lt;BR /&gt;
&lt;BR /&gt;
So all I need is a function that gives me the value of "price_number" where "price_" is a prefix and number is the value of another variable in the same observation.</description>
      <pubDate>Mon, 29 Mar 2010 22:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72289#M15587</guid>
      <dc:creator>mattb</dc:creator>
      <dc:date>2010-03-29T22:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: addressing a variable by using another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72290#M15588</link>
      <description>You have a prefix constant 'price_' (or maybe it is stored in a SAS variable) and you have another SAS variable that contains a number (suffix) the one that identifies your desired variable with the data-value.&lt;BR /&gt;
&lt;BR /&gt;
In a DATA step, use the VVALUEX function and concatenate the variable pieces together to construct a string which in itself is the SAS variable you want to reference.&lt;BR /&gt;
&lt;BR /&gt;
Have a look at the SAS Language Reference and the VVAULEX function discussion, closely.  Here's a link:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a002233818.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a002233818.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic/post:&lt;BR /&gt;
vvaluex function site:sas.com</description>
      <pubDate>Mon, 29 Mar 2010 23:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72290#M15588</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-03-29T23:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: addressing a variable by using another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72291#M15589</link>
      <description>Thanks a lot! It is working perfectly!</description>
      <pubDate>Tue, 30 Mar 2010 09:12:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72291#M15589</guid>
      <dc:creator>mattb</dc:creator>
      <dc:date>2010-03-30T09:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: addressing a variable by using another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72292#M15590</link>
      <description>I must have missed something in your original description because I was thinking ARRAY.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data a;&lt;BR /&gt;
   array day_[5];&lt;BR /&gt;
   input day_&lt;LI&gt;;&lt;BR /&gt;
   n = ceil(ranuni(11345)*dim(day_));&lt;BR /&gt;
   result = day_&lt;N&gt;;&lt;BR /&gt;
   cards;&lt;BR /&gt;
1 2 3 4 5&lt;BR /&gt;
5 6 7 8 9&lt;BR /&gt;
3 4 5 6 7 &lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;/N&gt;&lt;/LI&gt;</description>
      <pubDate>Tue, 30 Mar 2010 13:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72292#M15590</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-03-30T13:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: addressing a variable by using another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72293#M15591</link>
      <description>You have this problem because you are violating an old programming truism: information belongs in variable &lt;B&gt;values&lt;/B&gt;, not in variable &lt;B&gt;names&lt;/B&gt;.&lt;BR /&gt;
&lt;BR /&gt;
The eliminate this, transpose the data set (proc transpose with the name option will do this easily) so your new structure has two fields, like this:&lt;BR /&gt;
&lt;BR /&gt;
Day  Value&lt;BR /&gt;
1       1234&lt;BR /&gt;
2        5678&lt;BR /&gt;
3        whatever&lt;BR /&gt;
&lt;BR /&gt;
Your problem has just gone away.  You can find the day(s) you want with a subsetting if or a where statement or data set option.  The where can be used in a proc step as well, saving preproceesing.&lt;BR /&gt;
&lt;BR /&gt;
Cheers, &lt;BR /&gt;
&lt;BR /&gt;
Jonathan&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; hello,&lt;BR /&gt;
&amp;gt; i have the following problem: For each observation in&lt;BR /&gt;
&amp;gt; my dataset i have hundreds of columns. They are&lt;BR /&gt;
&amp;gt; named: day_1 day_2 day_3 day_4 day_5.....&lt;BR /&gt;
&amp;gt; Then I have a variable that contains a number, let's&lt;BR /&gt;
&amp;gt; say n=4.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Now I want to create another variable, let's say&lt;BR /&gt;
&amp;gt; 'result', that is equal to day_n.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; In my example it should be: result = day_4&lt;BR /&gt;
&amp;gt; But n is not always 4. So I need a small programme&lt;BR /&gt;
&amp;gt; that helps me to solve that problem.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Thanks in advance for your help.&lt;BR /&gt;
&amp;gt; matt</description>
      <pubDate>Tue, 30 Mar 2010 16:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/addressing-a-variable-by-using-another-variable/m-p/72293#M15591</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-03-30T16:34:02Z</dc:date>
    </item>
  </channel>
</rss>

