<?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: how to pick variable names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-pick-variable-names/m-p/356609#M83627</link>
    <description>&lt;P&gt;Something simple? &amp;nbsp;No. &amp;nbsp;But the complexities are manageable. &amp;nbsp;Old-style program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc contents data=have out=_contents_ (keep=name where=(index(upcase(name), 'MI') &amp;gt; 0));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gives you a list of all the variable names. &amp;nbsp;Note that you can use dictionary.columns instead of PROC CONTENTS if that's something y ou are mildly familiar with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then get the list into a macro variable (again you have choices at this point, CALL EXECUTE being one alternative):&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 : varlist&amp;nbsp;separated by ' ' from _contents_;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, use the macro variable:&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;varlist);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you can add to the list of variables, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set have (keep=id &amp;amp;varlist);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, consider whether it would be safer (but still accurate) to search for "mi_" instead of "mi".&lt;/P&gt;</description>
    <pubDate>Sat, 06 May 2017 10:15:27 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-05-06T10:15:27Z</dc:date>
    <item>
      <title>how to pick variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pick-variable-names/m-p/356607#M83626</link>
      <description>&lt;P&gt;Dear SAS community:&lt;/P&gt;
&lt;P&gt;I have a large dataset with several thousand variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to pick variables using specific texts in their variable names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use this simple code to pick them:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data two; set one;&lt;/P&gt;
&lt;P&gt;keep mi:;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this picks up the variables that starts with the name "mi", such as mi_date, mi_size, and mi_treat, but cannot pick up hx_mi, time_mi, and chronic_mi_treat.&amp;nbsp; is there something simple I can use to pick out variables using "mi" in the variable names regardless of position?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2017 10:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pick-variable-names/m-p/356607#M83626</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2017-05-06T10:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to pick variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pick-variable-names/m-p/356609#M83627</link>
      <description>&lt;P&gt;Something simple? &amp;nbsp;No. &amp;nbsp;But the complexities are manageable. &amp;nbsp;Old-style program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc contents data=have out=_contents_ (keep=name where=(index(upcase(name), 'MI') &amp;gt; 0));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gives you a list of all the variable names. &amp;nbsp;Note that you can use dictionary.columns instead of PROC CONTENTS if that's something y ou are mildly familiar with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then get the list into a macro variable (again you have choices at this point, CALL EXECUTE being one alternative):&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 : varlist&amp;nbsp;separated by ' ' from _contents_;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, use the macro variable:&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;varlist);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you can add to the list of variables, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set have (keep=id &amp;amp;varlist);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, consider whether it would be safer (but still accurate) to search for "mi_" instead of "mi".&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2017 10:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pick-variable-names/m-p/356609#M83627</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-06T10:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to pick variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pick-variable-names/m-p/356615#M83628</link>
      <description>&lt;P&gt;many thanks Astounding,&lt;/P&gt;
&lt;P&gt;fantastic, this is simple enough&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2017 11:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pick-variable-names/m-p/356615#M83628</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2017-05-06T11:05:49Z</dc:date>
    </item>
  </channel>
</rss>

