<?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: The reverse-vname function - how do I get the value of a variable via its name? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271142#M53942</link>
    <description>&lt;P&gt;I agree that dictionary.tables (or sashelp.vtable) can be problematic, especially if the library contains views of external databases which it has to look through, because of&amp;nbsp; columns like nobs. I've never, or rarely, had problems with dictionary.columns however. And f you're explicit about the libname and memname, the internal indexing is very efficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again in this case I knew the libname&amp;nbsp;contained no views and it returned the response effectively instantly.&lt;/P&gt;</description>
    <pubDate>Wed, 18 May 2016 00:06:38 GMT</pubDate>
    <dc:creator>LaurieF</dc:creator>
    <dc:date>2016-05-18T00:06:38Z</dc:date>
    <item>
      <title>The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270829#M53854</link>
      <description>&lt;P&gt;I'm trying, relatively successfully, to troll through a very large dataset (with 900-1,000 variables) finding variables which are never populated: every observation is missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At an observation level this is easy:&lt;/P&gt;&lt;P&gt;array char_var _char_;&lt;/P&gt;&lt;P&gt;do over char_var;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if missing(char_var) then...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I want to do it as efficiently as possible over the whole dataset. So I've populated a hash with the variable names via vname(char_var), and that works well. Putting the variable's name into the hash is fine. And removing it when I find a non-missing value is fine too. But I'd like to extract the variable's name from the hash and check whether that variable's &lt;EM&gt;value&lt;/EM&gt; is missing - similar to &amp;amp;&amp;amp;varname in macro code. Iterating over &lt;EM&gt;all&lt;/EM&gt; the elements in the array is time-consuming, when I could just do it over the remnants of the hash.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there some obvious solution that I'm missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Laurie&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 00:20:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270829#M53854</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-05-17T00:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270842#M53857</link>
      <description>&lt;P&gt;Check function &amp;nbsp;VVALUEX()&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 01:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270842#M53857</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-17T01:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270844#M53858</link>
      <description>&lt;P&gt;Brilliant! I was getting close with vvalue, but the extra letter on the function made all the difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Laurie&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 01:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270844#M53858</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-05-17T01:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270855#M53860</link>
      <description>&lt;P&gt;I would look for the maximums.&amp;nbsp;&amp;nbsp;If the maximum is missing then all values are missing.&lt;/P&gt;
&lt;P&gt;Maybe something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set SASHELP.HEART(obs=1);
  length VARNAME $32;
  call execute('proc sql; create table MAX as select ');
  do I=1 to 1e9 ;
     call vnext(VARNAME);
     if VARNAME eq 'VARNAME' then leave;
     if I &amp;gt; 1 then call execute(',');
     call execute(cats('max(',VARNAME,') as '||VARNAME));
   end;
   call execute(' from SASHELP.HEART;quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once the heavyweight-lifting of scanning&amp;nbsp;the table is done in one efficient pass, you only have this one-row table to parse.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 02:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270855#M53860</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-05-17T02:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270856#M53861</link>
      <description>&lt;P&gt;NLEVELS option in proc freq?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 02:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270856#M53861</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-17T02:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270870#M53867</link>
      <description>&lt;P&gt;966 variables, observation length of over 7k, 20.3 million rows - that's never going to fly.&amp;nbsp;But thanks anyway.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's best to treat it one row at a time. I think reducing the number of variables the require checking (down to around 400-odd, I think) each time is the most efficient way. In a couple of hash tables using up a maximum of 30k each, it keeps IO down to a minimum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Multi-threaded DS2 would be even better probably, if I had the time to become proficient in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="1"&gt;data &amp;amp;_output;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;set &amp;amp;_input(&amp;amp;_INPUT1_options) end=eof;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;array char_var _char_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;array num_var _numeric_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;if _n_ = 1 then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; length varname varname_remove $ 32;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; dcl hash variables(ordered: 'n');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; variables.defineKey('varname');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; variables.defineDone();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; dcl hiter variables_iter('variables');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; dcl hash remove_variables(ordered: 'n');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; remove_variables.defineKey('varname_remove');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; remove_variables.defineDone();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; dcl hiter remove_iter('remove_variables');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; do over char_var;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varname = vname(char_var);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; variables.add();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; do over num_var;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varname = vname(num_var);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; variables.add();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;rc = variables_iter.first();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;rc = remove_variables.clear();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;do while(rc = 0);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; if strip(vvaluex(varname)) notin(' ', '.') then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varname_remove = varname;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; remove_variables.add();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; rc = variables_iter.next();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;if remove_variables.num_items then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; rc = remove_iter.first();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; do while(rc = 0);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varname = varname_remove;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; variables.check();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; variables.remove();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc = remove_iter.next();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;variable_count = variables.num_items;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;if variable_count ne lag(variable_count) then&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; output;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;if eof;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;variable_count = variables.num_items;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;put variable_count 'variables left in hash.';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;rc = variables_iter.first();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;do while(not rc);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; put varname @;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; rc = variables_iter.next();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 04:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270870#M53867</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-05-17T04:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270873#M53870</link>
      <description>&lt;P&gt;Never gonna fly? Why?&lt;/P&gt;
&lt;P&gt;Done and dusted in 5 min on my 4-core windows box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE(compress=no);
 array A [999];
 do i=1 to 20e6;
   output; 
 end;
run;

data _null_;
  set HAVE(obs=1);
  length VARNAME $32;
  call execute('proc sql; create table MAX as select ');
  do I=1 to 1e9 until(VARNAME='VARNAME');
     call vnext(VARNAME);
     if VARNAME eq 'VARNAME' then leave;
     if I &amp;gt; 1 then call execute(',');
     call execute(cats('max(',VARNAME,') as '||VARNAME));
   end;
   call execute(' from HAVE;quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;
&lt;P&gt;real time 5:02.24&lt;/P&gt;
&lt;P&gt;user cpu time 3:13.84&lt;/P&gt;
&lt;P&gt;system cpu time 1:46.11&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;memory 411383.68k&lt;/P&gt;
&lt;P&gt;OS Memory 445396.00k&lt;/P&gt;
&lt;P&gt;Timestamp 17/05/2016 04:51:30 PM&lt;/P&gt;
&lt;P&gt;Step Count 69 Switch Count 4642&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 04:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270873#M53870</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-05-17T04:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270874#M53871</link>
      <description>&lt;P&gt;No, I meant using NLEVELS in proc freq.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 04:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270874#M53871</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-05-17T04:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270876#M53872</link>
      <description>&lt;P&gt;Fair enough.&lt;BR /&gt;Single-pass bulk processing is normally the&amp;nbsp;preferred option for speed. How does the proc sql compare to the data step with your data?&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 05:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270876#M53872</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-05-17T05:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270888#M53875</link>
      <description>&lt;P&gt;I was quite pleased with my solution, but it was too heavy on resources. I stopped it after 30 minutes, and it still had a long way to go. Yours took&amp;nbsp;15 minutes. Nicely done.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I put this at the end of it to produce the analysis:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;data &amp;amp;_output(compress=no);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;set &amp;amp;_output;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;array char_var _char_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;array num_var _numeric_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;length varname $ 32;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;do over char_var;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; if missing(char_var) then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varname = vname(char_var);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; output;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;do over num_var;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; if missing(num_var) then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varname = vname(num_var);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; output;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 06:47:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270888#M53875</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-05-17T06:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270913#M53880</link>
      <description>&lt;P&gt;Glad it worked.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Your code, as sophisticated and clever as it is, spends its time fetching and looking up and testing and processing each individual value. Not too good when you have 20 billion of them....&lt;/P&gt;
&lt;P&gt;Plus the SQL is easier to maintain. Complex logic is required sometimes, but not here. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More performance tips in&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 09:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270913#M53880</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-05-17T09:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270915#M53881</link>
      <description>To be fair, as it gets to the end my code gets faster and faster, checking only 50-odd variables.&lt;BR /&gt;&lt;BR /&gt;But yes, you're right. Yours using the max function in sql without a 'group by' precludes sorting of all the variables, as is thus very efficient. I like it a lot.&lt;BR /&gt;&lt;BR /&gt;L&lt;BR /&gt;</description>
      <pubDate>Tue, 17 May 2016 09:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270915#M53881</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-05-17T09:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270919#M53882</link>
      <description>&lt;P&gt;Another way to do the post processing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;_output(keep=VARNAME compress=no);
  set &amp;amp;_output;
  length VARNAME TYPE $32;
   do i=1 to 1e6 until(VARNAME='VARNAME');
     call vnext(VARNAME,TYPE);       
     if vvaluex(VARNAME)=' ' | (TYPE='N' &amp;amp; left(vvaluex(VARNAME))=:'.') then output;
   end;
run;      &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 11:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/270919#M53882</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-05-17T11:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271120#M53931</link>
      <description>&lt;P&gt;Also note that function &lt;FONT face="courier new,courier"&gt;vvaluex()&lt;/FONT&gt; uses formatted values. So to test for actual missing values, we may need to strip the formats if you have any.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="SAS Monospace" size="1"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="SAS Monospace" size="1"&gt;datasets&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="SAS Monospace" size="1"&gt;lib&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="1"&gt;=WORK &lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="1"&gt;nolist&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="1"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="1"&gt;modify&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="1"&gt; HAVE; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="1"&gt;format&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="1"&gt; _ALL_; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="SAS Monospace" size="1"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="SAS Monospace" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 21:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271120#M53931</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-05-17T21:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271132#M53936</link>
      <description>&lt;P&gt;Quite so. However this is a fact table in a data warehouse, and thus all values (theoretically at least) are actual unformatted values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From&amp;nbsp;the "more than one way of skinning a cat" department: another way of generating the SQL:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="1"&gt;proc sql noprint;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;select cat('max(', strip(name), ') as ', strip(name))&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp; into :varstring separated by ', '&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp; from dictionary.columns&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;where libname = "%upcase(%scan(&amp;amp;_input, 1, .))"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; and memname = "%upcase(%scan(&amp;amp;_input, 2, .))";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;create table &amp;amp;_output as&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp; select &amp;amp;varstring&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from &amp;amp;_input(&amp;amp;_input_options);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="1"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 22:19:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271132#M53936</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-05-17T22:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271134#M53937</link>
      <description>&lt;P&gt;Yes this works too.&lt;/P&gt;
&lt;P&gt;Personally, I avoid querying the dictionary as it can be very sssllloooww when many tables are online,&amp;nbsp;especially RDBMS tables.&lt;/P&gt;
&lt;P&gt;As you say, poor cat...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 22:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271134#M53937</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-05-17T22:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271142#M53942</link>
      <description>&lt;P&gt;I agree that dictionary.tables (or sashelp.vtable) can be problematic, especially if the library contains views of external databases which it has to look through, because of&amp;nbsp; columns like nobs. I've never, or rarely, had problems with dictionary.columns however. And f you're explicit about the libname and memname, the internal indexing is very efficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again in this case I knew the libname&amp;nbsp;contained no views and it returned the response effectively instantly.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 00:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271142#M53942</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-05-18T00:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: The reverse-vname function - how do I get the value of a variable via its name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271174#M53948</link>
      <description>&lt;P&gt;Good to know. I'll try to access the variable-level dictionary again then.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 05:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-reverse-vname-function-how-do-I-get-the-value-of-a-variable/m-p/271174#M53948</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-05-18T05:15:36Z</dc:date>
    </item>
  </channel>
</rss>

