<?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: CSV Import - Add Column From File Name? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598932#M172809</link>
    <description>&lt;P&gt;If you want read all files in a directory with the same defined structure, you do not need ANY macro coding at all, as the infile statement accepts wildcards:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.class;
file '$HOME/classes/class1.txt' dlm=';' dsd;
if _n_ = 1
then do;
  put;
  put;
  put 'name;sex;age';
end;
put name sex age;
run;

data _null_;
set sashelp.class;
file '$HOME/classes/class2.txt' dlm=';' dsd;
if _n_ = 1
then do;
  put;
  put;
  put 'name;sex;age';
end;
put name sex age;
run;

data want;
length fname inf $200;
infile "$HOME/classes/*.txt" dlm=';' dsd filename=inf truncover;
informat
  name $8.
  sex $1.
;
fname = inf;
input name@;
if name not in ('','name');
input sex age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you need to be more selective, you can use a compound file reference:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename in ("$HOME/classes/class1.txt" "$HOME/classes/class2.txt");

data want;
length fname inf $200;
infile in dlm=';' dsd filename=inf truncover;
informat
  name $8.
  sex $1.
;
fname = inf;
input name@;
if name not in ('','name');
input sex age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so all you have to do is build the list of filenames for the filename statement. The read is then done in one single step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Oct 2019 06:21:14 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-10-24T06:21:14Z</dc:date>
    <item>
      <title>CSV Import - Add Column From File Name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598912#M172796</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From a SAS tutorial I found code to import multiple .csv files at the same time and it works well (code is below).&amp;nbsp; I will admit that I don't fully understand the code but I am wondering what code I would use to:&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp; firstobs = 6 instead of the 2 that it is currently set at (I don't see in the code where this setting is)&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp; each file name is the same format&amp;nbsp;i.e. facility_trend_888.csv, facility_trend_999.csv&amp;nbsp;etc. and I would like to create a column in the dataset of "facility" to equal the last 3 digits i.e. 888 for EACH row of data in the dataset.&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp; Is there a way to exclude empty rows upon import or do I just do that after the fact?&lt;/P&gt;
&lt;P&gt;4.&amp;nbsp; Is there code to then combine all datasets into one dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for any and all assistance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below works as it should by importing the datasets with each file being imported with the naming convention of dsn1, dsn2 etc. to equal the number of csv files in the identified folder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro drive(dir,ext); 
   %local cnt filrf rc did memcnt name; 
   %let cnt=0;          

   %let filrf=mydir;    
   %let rc=%sysfunc(filename(filrf,&amp;amp;dir)); 
   %let did=%sysfunc(dopen(&amp;amp;filrf));
    %if &amp;amp;did ne 0 %then %do;   
   %let memcnt=%sysfunc(dnum(&amp;amp;did));    

    %do i=1 %to &amp;amp;memcnt;              
                       
      %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);                    
                    
      %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
       %if %superq(ext) = %superq(name) %then %do;                         
          %let cnt=%eval(&amp;amp;cnt+1);       
          %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));  
          proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" out=dsn&amp;amp;cnt 
           dbms=csv replace;            
          run;          
       %end; 
      %end;  

    %end;
      %end;
  %else %put &amp;amp;dir cannot be open.;
  %let rc=%sysfunc(dclose(&amp;amp;did));      
             
 %mend drive;
 
%drive(E:\HIMS\TEST\Strokes\2019 20\HIT_Tool,csv) 

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Oct 2019 03:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598912#M172796</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2019-10-24T03:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: CSV Import - Add Column From File Name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598917#M172799</link>
      <description>&lt;P&gt;This is how I'd do it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* generate sample csv files ;
%macro create_csv(where);
   %let num=%eval(&amp;amp;num+123);  %* some random number ;
   filename csv "%sysfunc(pathname(work))\facility_trend_&amp;amp;num..csv";
   proc export data=sashelp.class(where=(&amp;amp;where)) file=csv dbms=csv replace;
   run;
%mend;
%let num=0;
%create_csv(%str(age=12))
%create_csv(%str(age=13))
%create_csv(%str(age=14))
%create_csv(%str(age=15))
%create_csv(%str(age=16))

* get a list of the files in the directory ;
%dirlist(dir=%sysfunc(pathname(work)),filter=basename=:'facility_trend_' and ext='csv')

* import each file, naming the dataset dsn#, where # is the row number from dirlist ;
%macro code;
%let fullname=%trim(&amp;amp;fullname);
%let num=&amp;amp;__iter__;
proc import file="&amp;amp;fullname" out=work.dsn&amp;amp;num dbms=csv replace;
   getnames=yes;
run;
%mend;
%loop_control(control=dirlist)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/dirlist.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 04:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598917#M172799</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-10-24T04:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: CSV Import - Add Column From File Name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598920#M172802</link>
      <description>&lt;P&gt;So I read your requirements more carefully...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC IMPORT of a CSV does some data checking under the covers, determining the data type and length from the input data, then generates a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is problematic when you want to append the data.&amp;nbsp; Even though your CSV file may have the same column structure, the data itself can mean the datasets won't append due to different structure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, this does not work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* generate sample csv files ;
%macro create_csv(where);
   %let num=%eval(&amp;amp;num+123);  %* some random number ;
   filename csv "%sysfunc(pathname(work))\facility_trend_&amp;amp;num..csv";
   proc export data=sashelp.zipcode(where=(&amp;amp;where)) file=csv dbms=csv replace;
   run;
%mend;
%let num=0;
%create_csv(%str(statecode='CA'))
%create_csv(%str(statecode='NY'))
%create_csv(%str(statecode='FL'))
%create_csv(%str(statecode='NC'))
%create_csv(%str(statecode='AZ'))

* get a list of the files in the directory ;
%dirlist(dir=%sysfunc(pathname(work)),filter=basename=:'facility_trend_' and ext='csv')

* import each file, naming the dataset dsn#, where # is the row number from dirlist ;
%macro code;
%let fullname=%trim(&amp;amp;fullname);
%let num=&amp;amp;__iter__;
proc import file="&amp;amp;fullname" out=work.dsn&amp;amp;num dbms=csv replace;
   getnames=yes;
run;
data &amp;amp;syslast;
   set &amp;amp;syslast (firstobs=6);
   if missing(cats(of _all_)) then delete;
run;
proc append data=&amp;amp;syslast out=final;
run;
%mend;

proc delete data=final;
run;

%loop_control(control=dirlist)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'd advise just letting PROC IMPORT do its thing for a single file, then cut-and-paste the code from the log and edit as required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, this does work (I've purposely over-allocated the problem columns from above):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* generate sample csv files ;
%macro create_csv(where);
   %let num=%eval(&amp;amp;num+123);  %* some random number ;
   filename csv "%sysfunc(pathname(work))\facility_trend_&amp;amp;num..csv";
   proc export data=sashelp.zipcode(where=(&amp;amp;where)) file=csv dbms=csv replace;
   run;
%mend;
%let num=0;
%create_csv(%str(statecode='CA'))
%create_csv(%str(statecode='NY'))
%create_csv(%str(statecode='FL'))
%create_csv(%str(statecode='NC'))
%create_csv(%str(statecode='AZ'))

* get a list of the files in the directory ;
%dirlist(dir=%sysfunc(pathname(work)),filter=basename=:'facility_trend_' and ext='csv')

* import each file, naming the dataset dsn#, where # is the row number from dirlist ;
%macro code;
%let fullname=%trim(&amp;amp;fullname);
%let num=&amp;amp;__iter__;
data DSN&amp;amp;num;
infile "&amp;amp;fullname" delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=6;
   informat ZIP best32. ;
   informat Y best32. ;
   informat X best32. ;
   informat ZIP_CLASS $1. ;
   informat CITY $1000. ;
   informat STATE best32. ;
   informat STATECODE $2. ;
   informat STATENAME $1000. ;
   informat COUNTY best32. ;
   informat COUNTYNM $1000. ;
   informat MSA best32. ;
   informat AREACODE best32. ;
   informat AREACODES $1000. ;
   informat TIMEZONE $1000. ;
   informat GMTOFFSET best32. ;
   informat DST $1. ;
   informat PONAME $1000. ;
   informat ALIAS_CITY $1000. ;
   informat ALIAS_CITYN $1000. ;
input
            ZIP
            Y
            X
            ZIP_CLASS $
            CITY $
            STATE
            STATECODE $
            STATENAME $
            COUNTY
            COUNTYNM $
            MSA
            AREACODE
            AREACODES $
            TIMEZONE $
            GMTOFFSET
            DST $
            PONAME $
            ALIAS_CITY $
            ALIAS_CITYN $
;
if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
if missing(cats(of _all_)) then delete;
run;
proc append data=&amp;amp;syslast out=final;
run;
%mend;

proc datasets lib=work nowarn nolist;
   delete final;
quit;

%loop_control(control=dirlist)
&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>Thu, 24 Oct 2019 04:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598920#M172802</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-10-24T04:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: CSV Import - Add Column From File Name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598932#M172809</link>
      <description>&lt;P&gt;If you want read all files in a directory with the same defined structure, you do not need ANY macro coding at all, as the infile statement accepts wildcards:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.class;
file '$HOME/classes/class1.txt' dlm=';' dsd;
if _n_ = 1
then do;
  put;
  put;
  put 'name;sex;age';
end;
put name sex age;
run;

data _null_;
set sashelp.class;
file '$HOME/classes/class2.txt' dlm=';' dsd;
if _n_ = 1
then do;
  put;
  put;
  put 'name;sex;age';
end;
put name sex age;
run;

data want;
length fname inf $200;
infile "$HOME/classes/*.txt" dlm=';' dsd filename=inf truncover;
informat
  name $8.
  sex $1.
;
fname = inf;
input name@;
if name not in ('','name');
input sex age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you need to be more selective, you can use a compound file reference:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename in ("$HOME/classes/class1.txt" "$HOME/classes/class2.txt");

data want;
length fname inf $200;
infile in dlm=';' dsd filename=inf truncover;
informat
  name $8.
  sex $1.
;
fname = inf;
input name@;
if name not in ('','name');
input sex age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so all you have to do is build the list of filenames for the filename statement. The read is then done in one single step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 06:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598932#M172809</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-24T06:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: CSV Import - Add Column From File Name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598938#M172811</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;'s approach is better than mine.&amp;nbsp; In particular, it will perform better than my approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In another post yesterday, I said "It is just as important to know when NOT to use a macro".&amp;nbsp; I should follow my own advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the OP stated:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;1.&amp;nbsp; firstobs = 6 instead of the 2 that it is currently set at (I don't see in the code where this setting is)&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I've changed your code to this (since I'm on EG on Windows):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let root=%sysfunc(pathname(work));
%macro create_file(filename);
   data _null_;
      set sashelp.class;
      file "&amp;amp;root\&amp;amp;filename" dlm=';' dsd;
      if _n_ = 1
      then do;
        put 'name;sex;age';
      end;
      put name sex age;
   run;
%mend;
%create_file(class1.txt)
%create_file(class2.txt)
%create_file(class3.txt)

%dirlist(dir=&amp;amp;root,filter=basename=:'class' and ext='txt');

data class;set sashelp.class;run;  * just so it shows in EG ;
data want;
   set dirlist (keep=fullname);
   end=0;
   do until (end);
      infile dummy delimiter = ';' dsd missover lrecl=32767 firstobs=6 end=end filevar=fullname;
      informat
         name $8.
         sex $1.
      ;
      input name sex age;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;This works, but is there a better approach (esp. one that doesn't require %dirlist)?&amp;nbsp; I tried filevar= + filename= but couldn't get it to work (and lost patience &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 08:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598938#M172811</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-10-24T08:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: CSV Import - Add Column From File Name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598988#M172817</link>
      <description>&lt;P&gt;Solutions could be:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use the option DATAROW=6 in PROC IMPORT to start reading from row 6&lt;/LI&gt;
&lt;LI&gt;Submit a datastep after PROC IMPORT to add the column.&lt;/LI&gt;
&lt;LI&gt;You can use a WHERE clause on the output dataset&lt;/LI&gt;
&lt;LI&gt;Use PROC APPEND&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro drive(dir,ext); 
   %local cnt filrf rc did memcnt name; 
   %let cnt=0;          

   %let filrf=mydir;    
   %let rc=%sysfunc(filename(filrf,&amp;amp;dir)); 
   %let did=%sysfunc(dopen(&amp;amp;filrf));
    %if &amp;amp;did ne 0 %then %do;   
   %let memcnt=%sysfunc(dnum(&amp;amp;did));    

    %do i=1 %to &amp;amp;memcnt;              
                       
      %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);                    
                    
      %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
       %if %superq(ext) = %superq(name) %then %do;                         
          %let cnt=%eval(&amp;amp;cnt+1);       
          %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));  
          proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" out=dsn&amp;amp;cnt(where=(X is not NULL)) 
           dbms=csv replace datarow=6;            
          run;     
  data  dsn&amp;amp;cnt;
    set dsn&amp;amp;cnt;
      length file_ID $10;
      retain File_ID "&amp;amp;cnt"; /* Or whatever you want to use to identify the file */
  run;
  proc append base=Facility force;
  run;
       %end; 
      %end;  

    %end;
      %end;
  %else %put &amp;amp;dir cannot be open.;
  %let rc=%sysfunc(dclose(&amp;amp;did));      
             
 %mend drive;
 
%drive(E:\HIMS\TEST\Strokes\2019 20\HIT_Tool,csv) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PROC APPEND will not work if SAS interprets data from different files differently, and you may have problems with the data being truncated, if columns in the first file are shorter than in some of the following files. In that case, you may have to use the data step generated by PROC IMPORT, with modifications, instead of PROC IMPORT itself - press F4 (RECALL) after submitting a PROC IMPORT of one file, and then modify that code and use it instead of PROC IMPORT.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 12:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598988#M172817</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-10-24T12:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: CSV Import - Add Column From File Name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598992#M172819</link>
      <description>&lt;P&gt;I use this condition&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if name not in ('','name');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to jump over my artificially included "header" lines. This condition needs to be adapted to the actual content (or non-content) of the 5 lines in every file that need to be skipped.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 12:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/598992#M172819</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-24T12:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: CSV Import - Add Column From File Name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/599038#M172840</link>
      <description>&lt;P&gt;Do you not know what is in the CSV files?&amp;nbsp; Why are you using PROC IMPORT instead of just writing your own data step to read the file?&lt;/P&gt;
&lt;P&gt;Once you know how to read one file you should be able to read them all using a wildcard in the input filename.&amp;nbsp; You can use the FILENAME= option on the INFILE statement to get access to which file you are reading.&amp;nbsp; You can use the change in input filename to know when you need to skip header rows.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length fname $256 facility $3 ;
  infile 'E:\HIMS\TEST\Strokes\2019 20\HIT_Tool\facility_trend_*.csv'
         dsd filename=fname truncover 
  ;
  input @;
  if fname ne lag(fname) then row=0;
  row+1;
  if row&amp;lt;6 then delete;
  length var1 8 var2 $20 .... var_last $4 ;
  input var1--var_last ;
  facility=substr(fname,length(fname)-6,3);
run;
     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So to adjust that program to your data just change these two lines to reflect your actual variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  length var1 8 var2 $20 .... var_last $4 ;
  input var1--var_last ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 14:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/599038#M172840</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-24T14:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: CSV Import - Add Column From File Name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/599072#M172856</link>
      <description>&lt;P&gt;Thank you so much to all who responded, I really appreciate it.&amp;nbsp; Tom, I did not know that you could use a wildcard for the infile statement so that will be life changing for future code!&amp;nbsp;&amp;nbsp; I also liked the simplicity of the code you provided and it worked like a charm.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a great day everyone!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 15:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Import-Add-Column-From-File-Name/m-p/599072#M172856</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2019-10-24T15:25:55Z</dc:date>
    </item>
  </channel>
</rss>

