<?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: Getting column names when using macro proc import in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/921690#M83364</link>
    <description>Also make sure you have set VALIDVARNAME=ANY.</description>
    <pubDate>Mon, 25 Mar 2024 11:33:11 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2024-03-25T11:33:11Z</dc:date>
    <item>
      <title>Getting column names when using macro proc import</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/920941#M83356</link>
      <description>&lt;DIV&gt;I am pulling 11 csv files over from my c: and the first row is not becoming the sas column names. The first field name is 'sep=' and the following field names are 'var1, var2, var3....etc'. I've tried using 'getnames' and the column names are still sep=, VAR1, VAR2...ect. Also the log shows informat as sep=n, VAR1, VAR2...etc. I've attached a test file as an example of my data. I'm not sure how to get SAS to grab the first row and make them column names.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp;Part of the log:&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-60px"&gt;informat "sep="N $12. ;&lt;BR /&gt;678 informat VAR2 $94. ;&lt;BR /&gt;679 informat VAR3 $16. ;&lt;BR /&gt;680 informat VAR4 $11. ;&lt;BR /&gt;681 informat VAR5 $11. ;&lt;BR /&gt;682 informat VAR6 $11. ;&lt;BR /&gt;683 informat VAR7 $11. ;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-60px"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-60px"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Import code:&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;%macro drive(dir,ext);&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp;%local cnt filrf rc did memcnt name;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp;%let cnt=0;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp;%let filrf=mydir;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp;%let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp;%let did=%sysfunc(dopen(&amp;amp;filrf));&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp;%if &amp;amp;did ne 0 %then %do;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %let memcnt=%sysfunc(dnum(&amp;amp;did));&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %do i=1 %to &amp;amp;memcnt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %if %superq(ext) = %superq(name) %then %do;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let cnt=%eval(&amp;amp;cnt+1);&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" out=dsn&amp;amp;cnt&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbms=csv replace;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&lt;SPAN&gt;getnames=yes;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;run;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%end;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%end;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; &amp;nbsp; %end;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; %else %put &amp;amp;dir cannot be opened.;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp; %let rc=%sysfunc(dclose(&amp;amp;did));&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;%mend drive;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-90px"&gt;%drive(C:\Users\Chelsea.H\Desktop\QSS_2022,csv);&lt;/DIV&gt;</description>
      <pubDate>Tue, 19 Mar 2024 16:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/920941#M83356</guid>
      <dc:creator>Chelsea8</dc:creator>
      <dc:date>2024-03-19T16:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Getting column names when using macro proc import</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/921680#M83363</link>
      <description>&lt;P&gt;Can you import a single csv-file using proc import, without using the macro, and get the columnnames?&lt;/P&gt;
&lt;P&gt;NOTE: I and many others don't open attached files because of security implications. Please include the first 3 lines of the csv (with only 3 or 4 columns) as code in the post so we can have a look.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 10:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/921680#M83363</guid>
      <dc:creator>JosvanderVelden</dc:creator>
      <dc:date>2024-03-25T10:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: Getting column names when using macro proc import</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/921690#M83364</link>
      <description>Also make sure you have set VALIDVARNAME=ANY.</description>
      <pubDate>Mon, 25 Mar 2024 11:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/921690#M83364</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2024-03-25T11:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: Getting column names when using macro proc import</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/921700#M83365</link>
      <description>&lt;P&gt;Which 11 files?&amp;nbsp; Which ONE of the 11 files is the one that is generating a variable name of SEP= ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You appear to be using a complex macro code to get the list of files.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the list is known just type (or copy and paste) the filenames.&lt;/P&gt;
&lt;P&gt;If the list is unknown and you need to use DREAD() to find the file names why are you doing it in macro code instead of in a dataset?&amp;nbsp; It is MUCH MUCH MUCH easier to debug normal SAS code than macro code.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 12:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/921700#M83365</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-25T12:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Getting column names when using macro proc import</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/921735#M83366</link>
      <description>Thank you! I have multiple people who have helped and this suggestion was the missing piece.</description>
      <pubDate>Mon, 25 Mar 2024 19:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-column-names-when-using-macro-proc-import/m-p/921735#M83366</guid>
      <dc:creator>Chelsea8</dc:creator>
      <dc:date>2024-03-25T19:27:15Z</dc:date>
    </item>
  </channel>
</rss>

