<?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 How to select variables having a particular string as part of its name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-variables-having-a-particular-string-as-part-of/m-p/359480#M84541</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;For your kind information, I am trying to select a group of variables having a particular string as part of its name. For e.g. from my dataset "HAVE", I want only those variable which are having " Completeness" as part of its name.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
input aa_completeness  bb_consistency bb_completeness cc_accuracy cc_completeness dd_consistency;
datalines ;
90 80 70 60 50 40
; 
run;


data want ;
input aa_completeness  bb_completeness cc_completeness ;
datalines ;
90 70 50
; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance for your kind reply to move forward.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 May 2017 20:12:00 GMT</pubDate>
    <dc:creator>DeepakSwain</dc:creator>
    <dc:date>2017-05-17T20:12:00Z</dc:date>
    <item>
      <title>How to select variables having a particular string as part of its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-variables-having-a-particular-string-as-part-of/m-p/359480#M84541</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;For your kind information, I am trying to select a group of variables having a particular string as part of its name. For e.g. from my dataset "HAVE", I want only those variable which are having " Completeness" as part of its name.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
input aa_completeness  bb_consistency bb_completeness cc_accuracy cc_completeness dd_consistency;
datalines ;
90 80 70 60 50 40
; 
run;


data want ;
input aa_completeness  bb_completeness cc_completeness ;
datalines ;
90 70 50
; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance for your kind reply to move forward.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 20:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-variables-having-a-particular-string-as-part-of/m-p/359480#M84541</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-05-17T20:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variables having a particular string as part of its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-variables-having-a-particular-string-as-part-of/m-p/359488#M84545</link>
      <description>&lt;P&gt;SAS gives you a couple of ways to capture variable names.&amp;nbsp; Here's one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc contents data=have noprint out=_contents_ (keep=name);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select strip(name) into : compl_list separated by ' '&lt;/P&gt;
&lt;P&gt;from _contents_&lt;/P&gt;
&lt;P&gt;where index(upcase(name), 'COMPLETENESS') &amp;gt; 0;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should give you a macro variable &amp;amp;COMPL_LIST that holds the names you are looking for.&amp;nbsp; Use as you need to, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have (keep=&amp;amp;COMPL_LIST);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 20:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-variables-having-a-particular-string-as-part-of/m-p/359488#M84545</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-17T20:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variables having a particular string as part of its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-variables-having-a-particular-string-as-part-of/m-p/359489#M84546</link>
      <description>&lt;P&gt;Something like the following should work. Note that in the Dictionary table that the variable Libname and Memname (the data set) are in upper case but Name (the variable name) may be mixed. So you want to consider case in comparisons. Any you really want to specify the library as if you have multiple libraries it will find the variables from all data sets with the same name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
   select name into : varnames separated by " "
   from dictionary.columns
   where libname="WORK" and memname="HAVE"
     and upcase(name) contains "COMPLETENESS";
quit;

data want;
   set have (keep = &amp;amp;varnames);
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2017 20:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-variables-having-a-particular-string-as-part-of/m-p/359489#M84546</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-17T20:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to select variables having a particular string as part of its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-variables-having-a-particular-string-as-part-of/m-p/359498#M84549</link>
      <description>&lt;P&gt;A pure data step solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename tmp temp;

data _null_;
  file tmp;
  if 0 then set have;
  length varname $32;
  do until (varname='varname');
    call vnext(varname);
    if index(varname,'_completeness') then put varname;
  end;
run;

data want;
   set have;
   keep
     %include tmp;
   ;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2017 21:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-variables-having-a-particular-string-as-part-of/m-p/359498#M84549</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-05-17T21:14:33Z</dc:date>
    </item>
  </channel>
</rss>

