<?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: Quick way to list out sequential variables with same prefix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Quick-way-to-list-out-sequential-variables-with-same-prefix/m-p/544457#M150574</link>
    <description>&lt;P&gt;1) Create an array of the 200 variables and use the WHICHC or WHICHN function to find the first occurrence of first_exvar being equal to one of the variables. If the function equals zero, then none of them does.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) PROC SQL does not support variable listing like this. However, check out KSharps approach in the thread below. I think that is the best way for you &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;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/td-p/390784" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/td-p/390784&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2019 07:20:43 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-03-20T07:20:43Z</dc:date>
    <item>
      <title>Quick way to list out sequential variables with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quick-way-to-list-out-sequential-variables-with-same-prefix/m-p/544446#M150569</link>
      <description>&lt;P&gt;I have two situations in which I need to list all of my variables (which are sequential and have the same prefix):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#1)&lt;/P&gt;&lt;P&gt;if age&amp;lt;60 or ^(first_exvar = other_var_1 or&amp;nbsp;first_exvar = other_var_2 or&amp;nbsp;first_exvar = other_var_3....first_exvar = other_var_200) then flag=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, I need to make sure the value of variable&amp;nbsp;&lt;STRONG&gt;first_exvar&lt;/STRONG&gt; does not equal the value of variables&amp;nbsp;&lt;STRONG&gt;other_var_1&lt;/STRONG&gt; through to&amp;nbsp;&lt;STRONG&gt;other_var_200&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the best way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#2)&lt;/P&gt;&lt;P&gt;This is slight different than above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table ex_table as&lt;BR /&gt;select distinct idnum, date, age, max(visitnum) as maxvisitnum, other_var_1, other_var_2, other_var_3....other_var_200&lt;/P&gt;&lt;P&gt;from data&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to select all variables from&amp;nbsp;&lt;STRONG&gt;other_var_1&lt;/STRONG&gt; to&amp;nbsp;&lt;STRONG&gt;other_var_200?&lt;/STRONG&gt;&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;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 06:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quick-way-to-list-out-sequential-variables-with-same-prefix/m-p/544446#M150569</guid>
      <dc:creator>soomx</dc:creator>
      <dc:date>2019-03-20T06:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Quick way to list out sequential variables with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quick-way-to-list-out-sequential-variables-with-same-prefix/m-p/544457#M150574</link>
      <description>&lt;P&gt;1) Create an array of the 200 variables and use the WHICHC or WHICHN function to find the first occurrence of first_exvar being equal to one of the variables. If the function equals zero, then none of them does.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) PROC SQL does not support variable listing like this. However, check out KSharps approach in the thread below. I think that is the best way for you &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;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/td-p/390784" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Proc-sql-select-group-variable-with-same-prefix/td-p/390784&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 07:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quick-way-to-list-out-sequential-variables-with-same-prefix/m-p/544457#M150574</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-20T07:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Quick way to list out sequential variables with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quick-way-to-list-out-sequential-variables-with-same-prefix/m-p/544461#M150578</link>
      <description>&lt;P&gt;You can create a dynamic piece of code and store it in a macro variable for use in the data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input age first_exvar other_var_1 other_var_2;
cards;
60 1 2 1
;
run;

proc sql noprint;
select "first_exvar = " !! name into :compare_str separated by " or "
from dictionary.columns
where libname = 'WORK' and memname = 'HAVE' and upcase(name) like '%OTHER_VAR%';
quit;

%put &amp;amp;compare_str.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log excerpt:&lt;/P&gt;
&lt;PRE&gt;40         %put &amp;amp;compare_str.;
first_exvar = other_var_1 or first_exvar = other_var_2
&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 07:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quick-way-to-list-out-sequential-variables-with-same-prefix/m-p/544461#M150578</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-20T07:25:49Z</dc:date>
    </item>
  </channel>
</rss>

