<?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 Soaking up file names from directory and tagging filename with a sequential counter in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616118#M18847</link>
    <description>&lt;P&gt;I am trying to adapt some code I found here (&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/PROC-APPEND-Alternatives/ta-p/475807" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/PROC-APPEND-Alternatives/ta-p/475807&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code should soak up all the data files in a folder, assign a sequential tag number to the end of the filename and, using a loop, append each of the now-sequentially numbered files to create a master file.&amp;nbsp; Basically, no matter the filename, it gets sucked up and appended (I am hoping!).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The steps in my modded code all seem to work, except for the Data _NULL_ step which assigns the sequential tag to the end of the filename.&amp;nbsp; Any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it matters, my filenames are similar to this (hrc_2018_9_targets_30_of_36.sas7bdat).&amp;nbsp; However, I have also tried this by renaming all of the files with a single letter and it still did not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET mydata=E:\SAS Data\Regression\2018 HRC Results Top 50 runs;

*List all the files in the current directory;

FILENAME dirlist PIPE "dir /B ""&amp;amp;mydata\*.sas7bdat""";
DATA dirlist;
LENGTH fname $256;
INFILE dirlist LENGTH=reclen TRUNCOVER;
INPUT fname $varying256. reclen;
put fname=;
RUN;

data WORK.dirlist;
    infile dirlist truncover; /* for more on truncover, see this paper and this blog post */
    input fname $40.; /* change if you expect longer file names */
run;

proc sql;
    select count(*)
    into :num_files
    from WORK.dirlist;
quit;

data _NULL_;
    set WORK.dirlist;
    call symputx(cats("file_", _N_), trim(fname));
run;

%macro readin;
%do i=1 %to &amp;amp;num_files;
    proc append base=full_set
                data=&amp;amp;file_&amp;amp;i;
    run;
%end;

%mend readin;
%readin;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jan 2020 06:20:52 GMT</pubDate>
    <dc:creator>texasmfp</dc:creator>
    <dc:date>2020-01-09T06:20:52Z</dc:date>
    <item>
      <title>Soaking up file names from directory and tagging filename with a sequential counter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616118#M18847</link>
      <description>&lt;P&gt;I am trying to adapt some code I found here (&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/PROC-APPEND-Alternatives/ta-p/475807" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/PROC-APPEND-Alternatives/ta-p/475807&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code should soak up all the data files in a folder, assign a sequential tag number to the end of the filename and, using a loop, append each of the now-sequentially numbered files to create a master file.&amp;nbsp; Basically, no matter the filename, it gets sucked up and appended (I am hoping!).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The steps in my modded code all seem to work, except for the Data _NULL_ step which assigns the sequential tag to the end of the filename.&amp;nbsp; Any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it matters, my filenames are similar to this (hrc_2018_9_targets_30_of_36.sas7bdat).&amp;nbsp; However, I have also tried this by renaming all of the files with a single letter and it still did not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET mydata=E:\SAS Data\Regression\2018 HRC Results Top 50 runs;

*List all the files in the current directory;

FILENAME dirlist PIPE "dir /B ""&amp;amp;mydata\*.sas7bdat""";
DATA dirlist;
LENGTH fname $256;
INFILE dirlist LENGTH=reclen TRUNCOVER;
INPUT fname $varying256. reclen;
put fname=;
RUN;

data WORK.dirlist;
    infile dirlist truncover; /* for more on truncover, see this paper and this blog post */
    input fname $40.; /* change if you expect longer file names */
run;

proc sql;
    select count(*)
    into :num_files
    from WORK.dirlist;
quit;

data _NULL_;
    set WORK.dirlist;
    call symputx(cats("file_", _N_), trim(fname));
run;

%macro readin;
%do i=1 %to &amp;amp;num_files;
    proc append base=full_set
                data=&amp;amp;file_&amp;amp;i;
    run;
%end;

%mend readin;
%readin;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 06:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616118#M18847</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-09T06:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Soaking up file names from directory and tagging filename with a sequential counter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616124#M18848</link>
      <description>&lt;P&gt;As far as I see, your macro variables contain filenames, not dataset names, so you need to put them in quotes in the append step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And why don't you go the simple way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname inlib "&amp;amp;mydata";

data _null_;
set sashelp.vtable;
where libname = "INLIB";
call execute(cats('proc append base=full_set data=inlib.',memname,';run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jan 2020 06:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616124#M18848</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-09T06:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Soaking up file names from directory and tagging filename with a sequential counter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616126#M18849</link>
      <description>&lt;P&gt;Thanks Kurt.&lt;/P&gt;
&lt;P&gt;what is this? set sashelp.vtable;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 06:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616126#M18849</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-09T06:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Soaking up file names from directory and tagging filename with a sequential counter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616127#M18850</link>
      <description>&lt;P&gt;The SASHELP.V* "tables" are views on the dictionary tables available in proc sql.&lt;/P&gt;
&lt;P&gt;SASHELP.VTABLE is a SQL view defined for DICTIONARY.TABLES. It is built dynamically every time you use it, from the currently assigned libraries.&lt;/P&gt;
&lt;P&gt;So I first assign a libname to the directory, after which SASHELP.VTABLE will show me all datasets there; then I use this to create the append code.&lt;/P&gt;
&lt;P&gt;Another method would be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname inlib "&amp;amp;mydata";

proc sql noprint;
select catx('.',libname,memname) into :setnames separated by ' '
from dictionary.tables
where libname = 'INLIB';
quit;

data full_set;
set full_set &amp;amp;setnames.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which does all appends in one step.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 06:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616127#M18850</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-09T06:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Soaking up file names from directory and tagging filename with a sequential counter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616129#M18851</link>
      <description>Thanks, but I get an error with that code:&lt;BR /&gt;&lt;BR /&gt;86   DM 'CLEAR LOG; CLEAR OUTPUT'; RESETLINE;&lt;BR /&gt;1    options ExtendObsCounter=no;&lt;BR /&gt;2&lt;BR /&gt;3    %LET mydata=E:\SAS Data\Regression\2018 HRC Results Top 50 runs;&lt;BR /&gt;4    libname inlib "&amp;amp;mydata";&lt;BR /&gt;SYMBOLGEN:  Macro variable MYDATA resolves to E:\SAS Data\Regression\2018 HRC Results Top 50 runs&lt;BR /&gt;NOTE: Library INLIB does not exist.&lt;BR /&gt;5&lt;BR /&gt;6    proc sql noprint;&lt;BR /&gt;7    select catx('.',libname,memname) into :setnames separated by ' '&lt;BR /&gt;8    from dictionary.tables&lt;BR /&gt;9    where libname = 'INLIB';&lt;BR /&gt;NOTE: No rows were selected.&lt;BR /&gt;10   quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;      real time           0.21 seconds&lt;BR /&gt;      cpu time            0.01 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;11&lt;BR /&gt;12   data full_set;&lt;BR /&gt;13   set full_set &amp;amp;setnames.;&lt;BR /&gt;                  -&lt;BR /&gt;                  22&lt;BR /&gt;                  200&lt;BR /&gt;WARNING: Apparent symbolic reference SETNAMES not resolved.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;, CUROBS, END, INDSNAME, KEY,&lt;BR /&gt;              KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;BR /&gt;&lt;BR /&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;BR /&gt;&lt;BR /&gt;14   run;&lt;BR /&gt;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.FULL_SET may be incomplete.  When this step was stopped there were 0 observations and 0 variables.&lt;BR /&gt;WARNING: Data set WORK.FULL_SET was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;      real time           0.57 seconds&lt;BR /&gt;      cpu time            0.01 seconds&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Jan 2020 06:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616129#M18851</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-09T06:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Soaking up file names from directory and tagging filename with a sequential counter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616133#M18852</link>
      <description>&lt;P&gt;So it seems your SAS session cannot access the directory. Make sure that your E:\ drive is mounted on the SAS Server.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 07:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616133#M18852</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-09T07:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Soaking up file names from directory and tagging filename with a sequential counter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616134#M18853</link>
      <description>&lt;P&gt;I am pulling my hair out:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;1 DM 'CLEAR LOG; CLEAR OUTPUT'; RESETLINE;&lt;BR /&gt;1 options ExtendObsCounter=no;&lt;BR /&gt;2&lt;BR /&gt;3 LIBNAME INLIB 'E:\SAS Data\PMS Regression\2018 HRC Results Top 52 run';&lt;BR /&gt;NOTE: Libref INLIB was successfully assigned as follows:&lt;BR /&gt;Engine: V9&lt;BR /&gt;Physical Name: E:\SAS Data\PMS Regression\2018 HRC Results Top 52 run&lt;BR /&gt;3 ! /* (T) Location of company and&lt;BR /&gt;3 ! */&lt;BR /&gt;4&lt;BR /&gt;5&lt;BR /&gt;6 proc sql noprint;&lt;BR /&gt;7 select catx('.',libname,memname) into :setnames separated by ' '&lt;BR /&gt;8 from dictionary.tables&lt;BR /&gt;9 where libname = 'INLIB';&lt;BR /&gt;NOTE: No rows were selected.&lt;BR /&gt;10 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.50 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;11&lt;BR /&gt;12 data full_set;&lt;BR /&gt;13 set full_set &amp;amp;setnames.;&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;200&lt;BR /&gt;WARNING: Apparent symbolic reference SETNAMES not resolved.&lt;BR /&gt;ERROR: File WORK.FULL_SET.DATA does not exist.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;, CUROBS, END, INDSNAME, KEY,&lt;BR /&gt;KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;14 run;&lt;/P&gt;
&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.FULL_SET may be incomplete. When this step was stopped there were 0 observations and 0 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.91 seconds&lt;BR /&gt;cpu time 0.04 seconds&lt;/P&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 07:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616134#M18853</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-09T07:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Soaking up file names from directory and tagging filename with a sequential counter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616136#M18854</link>
      <description>&lt;P&gt;OK, so you now had the libname statement working. Inspect the library in the SAS Explorer to see if there are any datasets in there, or use proc datasets to list the contents.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 07:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616136#M18854</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-09T07:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: Soaking up file names from directory and tagging filename with a sequential counter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616279#M18874</link>
      <description>Looked at INLIB in SAS Explorer and it is empty</description>
      <pubDate>Thu, 09 Jan 2020 18:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616279#M18874</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-09T18:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Soaking up file names from directory and tagging filename with a sequential counter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616288#M18880</link>
      <description>Kurt:  I made some tweaks and reloaded the data into the folder.  Its seems to work now.  Thanks</description>
      <pubDate>Thu, 09 Jan 2020 19:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Soaking-up-file-names-from-directory-and-tagging-filename-with-a/m-p/616288#M18880</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-09T19:26:05Z</dc:date>
    </item>
  </channel>
</rss>

