<?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 SAS Tip: Easy Way to Get All Variable Names From a Dataset in SAS Tips from the Community</title>
    <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Easy-Way-to-Get-All-Variable-Names-From-a-Dataset/m-p/475815#M176</link>
    <description>&lt;P&gt;In the recent issue of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;SAS&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;TechReport, there was a tip for using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;%sysfunc&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to get all the variable names from a dataset and store them in a single&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;macro variable. In the referenced sample code there is an alternate way using the dictionary tables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="mw-geshi mw-code mw-content-ltr" dir="ltr"&gt;
&lt;DIV class="sas source-sas"&gt;
&lt;PRE class="de1"&gt;&lt;SPAN class="kw2"&gt;%macro&lt;/SPAN&gt; getvars&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;dsn&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
    &lt;SPAN class="kw2"&gt;%global&lt;/SPAN&gt; vlist;
    &lt;SPAN class="re1"&gt;proc sql&lt;/SPAN&gt;;
        &lt;SPAN class="kw4"&gt;select&lt;/SPAN&gt; name &lt;SPAN class="kw4"&gt;into&lt;/SPAN&gt;&amp;nbsp;:vlist separated &lt;SPAN class="kw4"&gt;by&lt;/SPAN&gt; &lt;SPAN class="st0"&gt;' '&lt;/SPAN&gt;
        &lt;SPAN class="kw4"&gt;from&lt;/SPAN&gt; dictionary.columns
        &lt;SPAN class="kw4"&gt;where&lt;/SPAN&gt; memname = &lt;SPAN class="kw3"&gt;upcase&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&lt;SPAN class="st0"&gt;"&amp;amp;dsn"&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
    &lt;SPAN class="kw6"&gt;quit&lt;/SPAN&gt;;
&lt;SPAN class="kw2"&gt;%mend&lt;/SPAN&gt;;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;This creates a macro variable called&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;BIG&gt;&lt;SPAN class="mw-geshi sas source-sas"&gt;&lt;SPAN class="re0"&gt;&amp;amp;vlist&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BIG&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;that will contain the names of all the variables in your dataset, separated by a space. If you want commas between the variable names, all you have to do is change the 'separated by' value from ' ' to ', '. The use of the upcase function in the where statement avoids problems with someone passing the dataset name in the wrong case. The global statement is needed since the macro variable created will not necessarily be available outside the macro without defining it as global.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;This tip was originally posted by Susan M on sasCommunity.org.&lt;/EM&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jul 2018 20:37:21 GMT</pubDate>
    <dc:creator>SAS_Tipster</dc:creator>
    <dc:date>2018-07-05T20:37:21Z</dc:date>
    <item>
      <title>SAS Tip: Easy Way to Get All Variable Names From a Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Easy-Way-to-Get-All-Variable-Names-From-a-Dataset/m-p/475815#M176</link>
      <description>&lt;P&gt;In the recent issue of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;SAS&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;TechReport, there was a tip for using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;%sysfunc&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to get all the variable names from a dataset and store them in a single&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;macro variable. In the referenced sample code there is an alternate way using the dictionary tables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="mw-geshi mw-code mw-content-ltr" dir="ltr"&gt;
&lt;DIV class="sas source-sas"&gt;
&lt;PRE class="de1"&gt;&lt;SPAN class="kw2"&gt;%macro&lt;/SPAN&gt; getvars&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;dsn&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
    &lt;SPAN class="kw2"&gt;%global&lt;/SPAN&gt; vlist;
    &lt;SPAN class="re1"&gt;proc sql&lt;/SPAN&gt;;
        &lt;SPAN class="kw4"&gt;select&lt;/SPAN&gt; name &lt;SPAN class="kw4"&gt;into&lt;/SPAN&gt;&amp;nbsp;:vlist separated &lt;SPAN class="kw4"&gt;by&lt;/SPAN&gt; &lt;SPAN class="st0"&gt;' '&lt;/SPAN&gt;
        &lt;SPAN class="kw4"&gt;from&lt;/SPAN&gt; dictionary.columns
        &lt;SPAN class="kw4"&gt;where&lt;/SPAN&gt; memname = &lt;SPAN class="kw3"&gt;upcase&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;(&lt;/SPAN&gt;&lt;SPAN class="st0"&gt;"&amp;amp;dsn"&lt;/SPAN&gt;&lt;SPAN class="br0"&gt;)&lt;/SPAN&gt;;
    &lt;SPAN class="kw6"&gt;quit&lt;/SPAN&gt;;
&lt;SPAN class="kw2"&gt;%mend&lt;/SPAN&gt;;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;This creates a macro variable called&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;BIG&gt;&lt;SPAN class="mw-geshi sas source-sas"&gt;&lt;SPAN class="re0"&gt;&amp;amp;vlist&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BIG&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;that will contain the names of all the variables in your dataset, separated by a space. If you want commas between the variable names, all you have to do is change the 'separated by' value from ' ' to ', '. The use of the upcase function in the where statement avoids problems with someone passing the dataset name in the wrong case. The global statement is needed since the macro variable created will not necessarily be available outside the macro without defining it as global.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;This tip was originally posted by Susan M on sasCommunity.org.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 20:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Easy-Way-to-Get-All-Variable-Names-From-a-Dataset/m-p/475815#M176</guid>
      <dc:creator>SAS_Tipster</dc:creator>
      <dc:date>2018-07-05T20:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Tip: Easy Way to Get All Variable Names From a Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Easy-Way-to-Get-All-Variable-Names-From-a-Dataset/m-p/701397#M204</link>
      <description>&lt;P&gt;Should include LIBNAME as well.&lt;/P&gt;
&lt;P&gt;I know I have multiple libraries that might have the same data set names (related projects).&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 23:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Easy-Way-to-Get-All-Variable-Names-From-a-Dataset/m-p/701397#M204</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-24T23:28:31Z</dc:date>
    </item>
  </channel>
</rss>

