<?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: Error in pulling over column names using proc import multiple csv files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921736#M362968</link>
    <description>Thank you! This got me almost there. Someone from another thread suggested adding VALIDVARNAME=ANY which got the name to come over.</description>
    <pubDate>Mon, 25 Mar 2024 19:30:07 GMT</pubDate>
    <dc:creator>Chelsea8</dc:creator>
    <dc:date>2024-03-25T19:30:07Z</dc:date>
    <item>
      <title>Error in pulling over column names using proc import multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921142#M362751</link>
      <description>&lt;LI-SPOILER&gt;&amp;nbsp;&lt;/LI-SPOILER&gt;&lt;DIV&gt;I am pulling 11 csv files over from my local 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>Wed, 20 Mar 2024 16:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921142#M362751</guid>
      <dc:creator>Chelsea8</dc:creator>
      <dc:date>2024-03-20T16:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Error in pulling over column names using proc import multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921146#M362753</link>
      <description>&lt;P&gt;The file you showed does not have a variable named SEP=.&lt;/P&gt;
&lt;P&gt;Did you try to read in your SAS program as if it was a CSV file?&amp;nbsp; That might have SEP= in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    data _null_;
2      infile 'c:\downloads\testsas.csv' obs=5;
3      input;
4      list;
5    run;

NOTE: A byte-order mark in the file "c:\downloads\testsas.csv" (for fileref "#LN00102") indicates that the data is encoded in
      "utf-8".  This encoding will be used to process the file.
NOTE: The infile 'c:\downloads\testsas.csv' is:
      (system-specific pathname),
      (system-specific file attributes)

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
1         Identifier,HierarchyComponent,ComponentScore,CutPoint1,CutPoint2,CutPoint3,CutPoint4,Rating,MeasureS
     101  core,RawValue,Denominator,EligiblePopulation,Percentile5th,Percentile10th,Percentile25th,Percentile5
     201  0th,Percentile75th,Percentile90th,Percentile95th,Mean,StdDeviation,Min,Max,MeasureBenchmark 291
2         GLOBAL,Global,56.87,60,70,80,90,2,,,,,,,,,,,,,,,, 49
3         S1,SI: Clinical Quality Management,14.987,60,70,80,90,3,,,,,,,,,,,,,,,, 71
4         S1M49,M: Asthma Medication Ratio,,,,,,,64.333,0.99,354,654,0.688,0.72,0.768,0.845,0.892,0.915,0.945,
     101  0.827,0.084,0.57,1,0.925 124
5         S1M49a,MI: Asthma Medication Ratio (5-11),,,,,,,,0.75,8,8,,,,,,,,,,,, 69
NOTE: 5 records were read from the infile (system-specific pathname).
      The minimum record length was 49.
      The maximum record length was 291.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if you are reading many CSV files that all have the same variables in the same order then just read them all in one data step.&amp;nbsp; You can use the FILENAME= option on the INFILE statement to create a variable with the name of the current file being read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if all of the files look like the one you shared the program might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fromcsv;
  infile 'C:\Users\Chelsea.H\Desktop\QSS_*.csv' dlm=',' dsd truncover filename=fname;
  length Identifier $6 HierarchyComponent $35 ComponentScore 8 CutPoint1 8
    CutPoint2 8 CutPoint3 8 CutPoint4 8 Rating 8 MeasureScore 8 RawValue 8
    Denominator 8 EligiblePopulation 8 Percentile5th 8 Percentile10th 8
    Percentile25th 8 Percentile50th 8 Percentile75th 8 Percentile90th 8
    Percentile95th 8 Mean 8 StdDeviation 8 Min 8 Max 8 MeasureBenchmark 8
  ;
  input @;
  if fname ne lag(fname) then delete;
  input Identifier -- MeasureBenchmark ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2024 17:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921146#M362753</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-20T17:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Error in pulling over column names using proc import multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921161#M362758</link>
      <description>&lt;P&gt;This works great. Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am unable to grab the file name to create a column however. I need the 4 characters to the left of underscrore here: \2022_ (where the * is). When I input positive number it brings back error: (substr function call has too many arguments). When it is negative I either get blank or 'User' with smaller negative numbers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data fromcsv;&lt;BR /&gt;infile 'C:\Users\Chelsea.H\Desktop\QRR_2022\2022_*.csv' dlm=',' dsd truncover filename=fname;&lt;BR /&gt;length Identifier $6 HierarchyComponent $35 ComponentScore 8 CutPoint1 8&lt;BR /&gt;CutPoint2 8 CutPoint3 8 CutPoint4 8 Rating 8 MeasureScore 8 RawValue 8&lt;BR /&gt;Denominator 8 EligiblePopulation 8 Percentile5th 8 Percentile10th 8&lt;BR /&gt;Percentile25th 8 Percentile50th 8 Percentile75th 8 Percentile90th 8&lt;BR /&gt;Percentile95th 8 Mean 8 StdDeviation 8 Min 8 Max 8 MeasureBenchmark 8&lt;BR /&gt;;&lt;BR /&gt;input @;&lt;BR /&gt;if fname ne lag(fname) then delete;&lt;BR /&gt;input Identifier -- MeasureBenchmark ;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;QHP= substr(fname,length(fname)38,4);&lt;/FONT&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 18:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921161#M362758</guid>
      <dc:creator>Chelsea8</dc:creator>
      <dc:date>2024-03-20T18:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Error in pulling over column names using proc import multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921164#M362759</link>
      <description>&lt;P&gt;Perhaps this gives you an alternate:&lt;/P&gt;
&lt;PRE&gt;data example;
   fname='C:\Users\Chelsea.H\Desktop\QRR_2022\2022_*.csv';
   length QHP $ 4.;
   qhp = scan(fname,-1,'\');
run;&lt;/PRE&gt;
&lt;P&gt;Scan doesn't mind negatives as long you don't exceed the number of substrings separated by the provided delimiter (at which point you get missing values). -1 asks for the last "word" where words in this string are separated by the \ character only.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 18:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921164#M362759</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-20T18:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Error in pulling over column names using proc import multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921167#M362761</link>
      <description>&lt;P&gt;Using SCAN() is much easier.&amp;nbsp; Since you seem to want the first four characters of the actual name of the file (ignoring the path) you could just set the length of variable to $4 and then SAS will truncate it to 4 bytes since there is no place to store the other characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fromcsv;
infile 'C:\Users\Chelsea.H\Desktop\QRR_2022\2022_*.csv' dlm=',' dsd truncover filename=fname;
length QHP $4;
length Identifier $6 HierarchyComponent $35 ComponentScore 8 CutPoint1 8
CutPoint2 8 CutPoint3 8 CutPoint4 8 Rating 8 MeasureScore 8 RawValue 8
Denominator 8 EligiblePopulation 8 Percentile5th 8 Percentile10th 8
Percentile25th 8 Percentile50th 8 Percentile75th 8 Percentile90th 8
Percentile95th 8 Mean 8 StdDeviation 8 Min 8 Max 8 MeasureBenchmark 8
;
input @;
if fname ne lag(fname) then delete;
input Identifier -- MeasureBenchmark ;
QHP= scan(fname,-1,'/\') ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2024 19:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921167#M362761</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-20T19:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Error in pulling over column names using proc import multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921208#M362773</link>
      <description>&lt;P&gt;I've tried the follow and their results: -1 (user), 1 (c:), 2 (user), 3 (error improper order), 4 (blank), 5 (blank), -5 (blank)&lt;/P&gt;&lt;P&gt;I know that it should grab right to left when negative, but I don't see that happening, as -1 or -5 doesn't work. Totally stumped.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data fromcsv;&lt;BR /&gt;infile 'C:\Users\Chelsea.Ha-Co\Desktop\QRR_2022\2022_*.csv' dlm=',' dsd truncover filename=fname;&lt;BR /&gt;length QHP $4;&lt;BR /&gt;length Identifier $6 HierarchyComponent $35 ComponentScore 8 CutPoint1 8&lt;BR /&gt;CutPoint2 8 CutPoint3 8 CutPoint4 8 Rating 8 MeasureScore 8 RawValue 8&lt;BR /&gt;Denominator 8 EligiblePopulation 8 Percentile5th 8 Percentile10th 8&lt;BR /&gt;Percentile25th 8 Percentile50th 8 Percentile75th 8 Percentile90th 8&lt;BR /&gt;Percentile95th 8 Mean 8 StdDeviation 8 Min 8 Max 8 MeasureBenchmark 8;&lt;BR /&gt;input @;&lt;BR /&gt;if fname ne lag(fname) then delete;&lt;BR /&gt;input Identifier -- MeasureBenchmark ;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;QHP= scan(fname,3,'/\');&lt;/FONT&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 23:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921208#M362773</guid>
      <dc:creator>Chelsea8</dc:creator>
      <dc:date>2024-03-20T23:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Error in pulling over column names using proc import multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921212#M362774</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464599"&gt;@Chelsea8&lt;/a&gt;&amp;nbsp;Define the length for fname explicitly to avoid any risk of truncation. Then use scan() with -1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data fromcsv;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;length fname $1000 QHP $100;&lt;/FONT&gt;&lt;BR /&gt;infile 'C:\Users\Chelsea.Ha-Co\Desktop\QRR_2022\2022_*.csv' dlm=',' dsd truncover &lt;FONT color="#FF6600"&gt;filename=fname&lt;/FONT&gt;;&lt;BR /&gt;....&lt;BR /&gt;QHP= scan(fname,&lt;FONT color="#FF6600"&gt;-1,&lt;/FONT&gt;'\');&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 01:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921212#M362774</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-21T01:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Error in pulling over column names using proc import multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921736#M362968</link>
      <description>Thank you! This got me almost there. Someone from another thread suggested adding VALIDVARNAME=ANY which got the name to come over.</description>
      <pubDate>Mon, 25 Mar 2024 19:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-pulling-over-column-names-using-proc-import-multiple/m-p/921736#M362968</guid>
      <dc:creator>Chelsea8</dc:creator>
      <dc:date>2024-03-25T19:30:07Z</dc:date>
    </item>
  </channel>
</rss>

