<?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: Problem to retrieve column names using proc sql in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-to-retrieve-column-names-using-proc-sql/m-p/737283#M38710</link>
    <description>&lt;P&gt;Do you want the full list of problems? Or just the problems with the part that is trying to gather variable names?&lt;/P&gt;
&lt;P&gt;Let's start with the last step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * into :charlist separated by ' '
from dictionary.columns
where libname="work" and memname="birthday" 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Issues:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Add the NOPRINT option to the PROC SQL so the names are not also printed to the output window.&lt;/LI&gt;
&lt;LI&gt;Specify the actual value you want to put into the macro variable.&amp;nbsp; This would only select the variable NAME if that happens to be the first variable that would get selected by the * shortcut for all varaibles.&lt;/LI&gt;
&lt;LI&gt;Values of LIBNAME and MEMNAME are always uppercase in the DICTIONARY.COLUMNS.&lt;/LI&gt;
&lt;LI&gt;Do you care what order the names appear in the list?&lt;/LI&gt;
&lt;LI&gt;You also need to protect in case VALIDVARNAME option is set to ANY.&amp;nbsp; That means some names might have spaces in them.&amp;nbsp; You can use the NLITERAL() function for example&amp;nbsp; Or use some other character as the separator in the list for values.&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select nliteral(name)
  into :charlist separated by ' '
  from dictionary.columns
  where libname="WORK" and memname="BIRTHDAY"
  order by varnum 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Apr 2021 14:22:56 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-04-27T14:22:56Z</dc:date>
    <item>
      <title>Problem to retrieve column names using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-to-retrieve-column-names-using-proc-sql/m-p/737177#M38699</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not manage to get column names from my dataset using proc sql.&lt;/P&gt;&lt;P&gt;What's wrong in the following example code ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.birthday;
  input @01 employee_id   6.
        @08 last_name     $10.
        @19 birthday      date7.;
  format employee_id   6.
         last_name     $10.
         birthday      date7.;
  datalines;
  1247 Garcia     04APR54
  1078 Gibson     23APR36
  1005 Knapp      06OCT38
  1024 Mueller    17JUN53
;
proc print data=work.birthday;
  title2 'SAS Data Set work.BIRTHDAY';
run;

proc sql;
select * into :charlist separated by ' '
from dictionary.columns
where libname="work" and memname="birthday" 
;
quit;&lt;/CODE&gt;&lt;/PRE&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, 27 Apr 2021 07:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-to-retrieve-column-names-using-proc-sql/m-p/737177#M38699</guid>
      <dc:creator>ctisseuil</dc:creator>
      <dc:date>2021-04-27T07:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Problem to retrieve column names using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-to-retrieve-column-names-using-proc-sql/m-p/737191#M38700</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360343"&gt;@ctisseuil&lt;/a&gt;,&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Write "&lt;FONT face="courier new,courier"&gt;select &lt;STRONG&gt;name&lt;/STRONG&gt;&lt;/FONT&gt; ..." instead of "&lt;FONT face="courier new,courier"&gt;select &lt;STRONG&gt;*&lt;/STRONG&gt;&lt;/FONT&gt; ..."&lt;/LI&gt;
&lt;LI&gt;Specify &lt;FONT face="courier new,courier"&gt;libname&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;memname&lt;/FONT&gt; values in &lt;FONT face="courier new,courier"&gt;UPPER CASE&lt;/FONT&gt;&amp;nbsp;in the WHERE clause.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 27 Apr 2021 08:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-to-retrieve-column-names-using-proc-sql/m-p/737191#M38700</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-04-27T08:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem to retrieve column names using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-to-retrieve-column-names-using-proc-sql/m-p/737201#M38701</link>
      <description>&lt;P&gt;And adding to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;: The values for libname and memname are always uppercase&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;where libname="WORK" and memname="BIRTHDAY"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 09:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-to-retrieve-column-names-using-proc-sql/m-p/737201#M38701</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-27T09:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem to retrieve column names using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-to-retrieve-column-names-using-proc-sql/m-p/737283#M38710</link>
      <description>&lt;P&gt;Do you want the full list of problems? Or just the problems with the part that is trying to gather variable names?&lt;/P&gt;
&lt;P&gt;Let's start with the last step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * into :charlist separated by ' '
from dictionary.columns
where libname="work" and memname="birthday" 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Issues:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Add the NOPRINT option to the PROC SQL so the names are not also printed to the output window.&lt;/LI&gt;
&lt;LI&gt;Specify the actual value you want to put into the macro variable.&amp;nbsp; This would only select the variable NAME if that happens to be the first variable that would get selected by the * shortcut for all varaibles.&lt;/LI&gt;
&lt;LI&gt;Values of LIBNAME and MEMNAME are always uppercase in the DICTIONARY.COLUMNS.&lt;/LI&gt;
&lt;LI&gt;Do you care what order the names appear in the list?&lt;/LI&gt;
&lt;LI&gt;You also need to protect in case VALIDVARNAME option is set to ANY.&amp;nbsp; That means some names might have spaces in them.&amp;nbsp; You can use the NLITERAL() function for example&amp;nbsp; Or use some other character as the separator in the list for values.&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select nliteral(name)
  into :charlist separated by ' '
  from dictionary.columns
  where libname="WORK" and memname="BIRTHDAY"
  order by varnum 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 14:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-to-retrieve-column-names-using-proc-sql/m-p/737283#M38710</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-27T14:22:56Z</dc:date>
    </item>
  </channel>
</rss>

