<?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 one variable to directly refer another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534906#M146836</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34415"&gt;@Andygray&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tested your code with a very very large dataset at my insurance company where we deal with humongous amounts of data and it's much slower than the array based solution I am afraid.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It might help to clarify this comment by including the example code as it may not be obvious which you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quite often Proc Transpose is not a rapid solution for processes involving&amp;nbsp;"humongous" data. So I am guessing that this refers to the transpose approach.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Feb 2019 16:23:40 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-02-12T16:23:40Z</dc:date>
    <item>
      <title>Use value of one variable to directly refer another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534851#M146815</link>
      <description>&lt;P&gt;Dear SAS experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering if there is an easy way to use the value a variable to directly refer to other variables.&lt;/P&gt;&lt;P&gt;For example, given the data set below&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;data have;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;input varIndex var_1 var_2 var_3 var_4;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;cards;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1 . . . .&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;3 . . . .&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2 . . . .&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to assign 1 to &lt;FONT face="courier new,courier"&gt;var_i&lt;/FONT&gt; where i is given by the value of &lt;FONT face="courier new,courier"&gt;varIndex&lt;/FONT&gt; such that the desired output will be&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;data want;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;input varIndex var_1 var_2 var_3 var_4;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;cards;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;1 1 . . .&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;3 . . 1 .&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;2 . 1 . .&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;set have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;array varArray (4) var_1 - var_4;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;do i = 1 to 4;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if i = varIndex then varArray(i) = 1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;end;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;and it worked. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I'm wondering instead of using a do&amp;nbsp;loop to search for the variable I want to refer, is there a more efficient and direct way (e.g. if I have var_1 - var_100000) to achieve that?&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Thanks for your help.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 14:18:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534851#M146815</guid>
      <dc:creator>skcussas</dc:creator>
      <dc:date>2019-02-12T14:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of one variable to directly refer another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534855#M146816</link>
      <description>&lt;P&gt;You don't need the loop, you can simplify your code to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input varIndex var_1 var_2 var_3 var_4;
cards;
1 . . . .
3 . . . .
2 . . . .
;
run;

data want;
   set have;
   array varArray (4) var_1 - var_4;
   varArray[varIndex] = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Feb 2019 14:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534855#M146816</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-02-12T14:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of one variable to directly refer another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534859#M146819</link>
      <description>Thanks for your response&lt;BR /&gt;&lt;BR /&gt;What if I have non-trivial variable names such as a, b, c, and d&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input varName$ a b c d;&lt;BR /&gt;cards;&lt;BR /&gt;a . . . .&lt;BR /&gt;c . . . .&lt;BR /&gt;d . . . .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Is there an efficient way to do that?&lt;BR /&gt;&lt;BR /&gt;Thanks again for your help.</description>
      <pubDate>Tue, 12 Feb 2019 14:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534859#M146819</guid>
      <dc:creator>skcussas</dc:creator>
      <dc:date>2019-02-12T14:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of one variable to directly refer another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534864#M146822</link>
      <description>&lt;P&gt;Loop once and retain with temp array&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input varName$ a b c d;
cards;
a . . . .
c . . . .
d . . . .
;
run;

data want;
set have;
array t(*) a--d;
array j(4) $ _temporary_;
if _n_=1 then 
do i=1 to dim(t);
j(i)=vname(t(i));
end;
k=whichc(varname,of j(*));
t(k)=1;
drop k i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 15:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534864#M146822</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-12T15:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of one variable to directly refer another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534865#M146823</link>
      <description>&lt;P&gt;Use a simple transpose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input varName$ a b c d;
cards;
a . . . .
c . . . .
d . . . .
;
run;

data intermed;
set have;
value = 1;
num = _n_;
run;

proc transpose data=intermed out=want (drop=_name_ num);
var value;
id varname;
by num;
copy varname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Feb 2019 15:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534865#M146823</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-12T15:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of one variable to directly refer another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534869#M146825</link>
      <description>&lt;P&gt;I wonder how that's efficient if OP's stated objective is efficiency?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 15:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534869#M146825</guid>
      <dc:creator>Andygray</dc:creator>
      <dc:date>2019-02-12T15:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of one variable to directly refer another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534874#M146827</link>
      <description>&lt;P&gt;Define "efficiency".&lt;/P&gt;
&lt;P&gt;For me, code that is completely data-driven, and needs no changes when incoming data changes, is most efficient.&lt;/P&gt;
&lt;P&gt;Depending on the way the data is created in the first place, the intermediate step might not be necessary at all. What is important here is that the wanted action is basically a transpose.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 15:27:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534874#M146827</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-12T15:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of one variable to directly refer another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534878#M146829</link>
      <description>&lt;P&gt;I tested your code with a very very large dataset at my insurance company where we deal with humongous amounts of data and it's much slower than the array based solution I am afraid.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 15:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534878#M146829</guid>
      <dc:creator>Andygray</dc:creator>
      <dc:date>2019-02-12T15:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of one variable to directly refer another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534895#M146834</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34415"&gt;@Andygray&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tested your code with a very very large dataset at my insurance company where we deal with humongous amounts of data and it's much slower than the array based solution I am afraid.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No problem with that. Maxim 29 leads to the simplest and easiest to maintain solution, but if following Maxim 30 reveals a real bottleneck, the more customized solution will make sense.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 16:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534895#M146834</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-12T16:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: Use value of one variable to directly refer another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534906#M146836</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34415"&gt;@Andygray&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tested your code with a very very large dataset at my insurance company where we deal with humongous amounts of data and it's much slower than the array based solution I am afraid.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It might help to clarify this comment by including the example code as it may not be obvious which you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quite often Proc Transpose is not a rapid solution for processes involving&amp;nbsp;"humongous" data. So I am guessing that this refers to the transpose approach.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 16:23:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-value-of-one-variable-to-directly-refer-another-variable/m-p/534906#M146836</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-12T16:23:40Z</dc:date>
    </item>
  </channel>
</rss>

