<?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: Reading a list of files and conditionally export the files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/210488#M39021</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've the following question as well. In below why one data step works and the other not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;DATA _null_;&lt;/EM&gt;&lt;BR /&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET InputSet NOBS=nobs;&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF nobs = 0 then PUT "ERROR:&amp;nbsp; InputSet Table is empty";&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Doesn't work. */&lt;/EM&gt;&lt;BR /&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;RUN;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;DATA _null_;&lt;/EM&gt;&lt;BR /&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF nobs = 0 then PUT "ERROR:&amp;nbsp; InputSet Table is empty";&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Works. */&lt;/EM&gt;&lt;BR /&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET InputSet NOBS=nobs;&lt;/EM&gt;&lt;BR /&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;RUN;&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 31 Aug 2015 12:14:17 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2015-08-31T12:14:17Z</dc:date>
    <item>
      <title>Reading a list of files and conditionally export the files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/210487#M39020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would request someone to give suggestion for my questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. I've a file called output_file.txt in unix and it has list of file names (e.g.) SASApp_STPServer_tmp_12345.log. Now I need to create a dataset by consolidating all the files read from &lt;SPAN style="font-size: 13.3333330154419px;"&gt;output_file.txt. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; Since files are coming from different systems (will have different folder structures) I can't use wildcards in infile statement like infile "/usr/sas/sas_config/Lev1/SASApp/Logs/SASApp_STPServer_tmp_*.log" dsd truncover filename=fname; However file layouts are same like below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data log_analysis;&lt;/P&gt;&lt;P&gt;length fname filename $200;&lt;/P&gt;&lt;P&gt;infile "/usr/sas/sas_config/Lev1/SASApp/Logs/&lt;SPAN style="font-size: 13.3333330154419px;"&gt;SASApp_STPServer_tmp_*.log&lt;/SPAN&gt;" dsd truncover filename=fname;&lt;/P&gt;&lt;P&gt;input var : $ 3000.;&lt;/P&gt;&lt;P&gt;filename=fname;&lt;/P&gt;&lt;P&gt;var1 = _infile_;&lt;/P&gt;&lt;P&gt;if var1 = :'201';&lt;/P&gt;&lt;P&gt;Date_TimeStamp= scan(var1,1," ");&lt;/P&gt;&lt;P&gt;Status = scan(var1,2," ");&lt;/P&gt;&lt;P&gt;Processid = scan(var1,3," ");&lt;/P&gt;&lt;P&gt;userid = scan(var1,4," ");&lt;/P&gt;&lt;P&gt;Details = scan(var1,-1,'-');&lt;/P&gt;&lt;P&gt;drop var var1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code will work only if file is from ' &lt;SPAN style="font-size: 13.3333330154419px;"&gt;/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/'. Now I would like to know, how should I tweak this code, if I want to read /usr/sas/tir/test/loganalysis/output_file.txt.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assume output_file.txt has filenmaes like &lt;SPAN style="font-size: 13.3333330154419px;"&gt;SASApp_STPServer_tmp_12345.log Java&lt;SPAN style="font-size: 13.3333330154419px;"&gt;App_STPServer_tmp_34745.log&amp;nbsp; Sharepoint&lt;SPAN style="font-size: 13.3333330154419px;"&gt;App_STPServer_tmp_72345.log&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. How to conditionally export the file?&amp;nbsp; e.g. I need to export .csv only if dataset has greater than 0 observations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 11:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/210487#M39020</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2015-08-31T11:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a list of files and conditionally export the files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/210488#M39021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've the following question as well. In below why one data step works and the other not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;DATA _null_;&lt;/EM&gt;&lt;BR /&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET InputSet NOBS=nobs;&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF nobs = 0 then PUT "ERROR:&amp;nbsp; InputSet Table is empty";&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Doesn't work. */&lt;/EM&gt;&lt;BR /&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;RUN;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;DATA _null_;&lt;/EM&gt;&lt;BR /&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF nobs = 0 then PUT "ERROR:&amp;nbsp; InputSet Table is empty";&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Works. */&lt;/EM&gt;&lt;BR /&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET InputSet NOBS=nobs;&lt;/EM&gt;&lt;BR /&gt;&lt;EM style="font-weight: inherit; font-family: inherit;"&gt;RUN;&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 12:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/210488#M39021</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2015-08-31T12:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a list of files and conditionally export the files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/210489#M39022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When the SET statement encounters an end-of-file condition, it immediately stops processing of the data step, including all statements that appear &lt;SPAN style="text-decoration: underline;"&gt;after&lt;/SPAN&gt; the SET statement in the data step.&lt;/P&gt;&lt;P&gt;So your IF in the first example is never executed in case no obs are present.&lt;/P&gt;&lt;P&gt;In the second example, the IF is executed before the SET can stop the datastep.&lt;/P&gt;&lt;P&gt;The constant (that's what it is, basically) nobs is set before the data step starts iterating.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 12:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/210489#M39022</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-08-31T12:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a list of files and conditionally export the files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/224998#M40388</link>
      <description>&lt;P&gt;Another way is to use an IF 0 THEN SET statement. During compilation time nobs is&amp;nbsp;assigned a value&amp;nbsp;but the SET statement never executes. This will save processing time especially if there are many observations in your data set.&amp;nbsp;Since the&amp;nbsp;SET statement will never execute order of the statements doesn't matter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA&amp;nbsp;_null_;&lt;/P&gt;&lt;P&gt;if 0 then set inputset nobs=nobs;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;IF nobs = 0 then PUT "ERROR:&amp;nbsp; InputSet Table is empty";&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;RUN;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2015 17:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/224998#M40388</guid>
      <dc:creator>michelle_delaurentis_sas_com</dc:creator>
      <dc:date>2015-09-10T17:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a list of files and conditionally export the files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/225000#M40389</link>
      <description>&lt;P&gt;You can use the filevar= option on the infile statement to read in multiple files into the same SAS data set, as illustrated in these Samples:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/kb/24712" target="_blank"&gt;http://support.sas.com/kb/24712&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/kb/24710" target="_blank"&gt;http://support.sas.com/kb/24710&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2015 17:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/225000#M40389</guid>
      <dc:creator>michelle_delaurentis_sas_com</dc:creator>
      <dc:date>2015-09-10T17:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a list of files and conditionally export the files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/225153#M40399</link>
      <description>&lt;P&gt;I've the code like below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dirlist;
  infile cards truncover;
  input file_names $300.;
  cards;
'/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-30_tmptcmlva2_19142.log'
'/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-29_tmptcmlva2_19142.log'
'/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-28_tmptcmlva2_19142.log'
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now I need to read all the files and append it to a single file as mentioned in data step. So I wrote a code as below. However, I could &amp;nbsp;not succeeed. See the log below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are records in my input files,but my code could not read it for some reasons. Please guide me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA output_data_set;
set dirlist;
/* read the file references in variable called file_names */
INFILE  IN dsd truncover FILEVAR = file_names END = end_of_file LRECL=32000;
     DO WHILE (end_of_file = 0);
        input var : $ 3000.;
/*filename=file_names;*/
var1 = _infile_;
if var1 = :'201';
Date_TimeStamp= scan(var1,1," ");
Status = scan(var1,2," ");
Processid = scan(var1,3," ");
userid = scan(var1,4," ");
Details = scan(var1,-1,'-');
drop var var1;
        OUTPUT;
     END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;4          data dirlist;
5            infile cards truncover;
6            input file_names $300.;
7            cards;

NOTE: The data set WORK.DIRLIST has 3 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds
      

7        !         
11         ;
12         run;
&amp;#12;2                                                          The SAS System                           08:36 Friday, September 11, 2015

13         
14         DATA output_data_set;
15         set dirlist;
16         /* read the file references in variable called file_names */
17         INFILE  IN dsd truncover FILEVAR = file_names END = end_of_file LRECL=32000;
18              DO WHILE (end_of_file = 0);
19                 input var : $ 3000.;
20         /*filename=file_names;*/
21         var1 = _infile_;
22         if var1 = :'201';
23         Date_TimeStamp= scan(var1,1," ");
24         Status = scan(var1,2," ");
25         Processid = scan(var1,3," ");
26         userid = scan(var1,4," ");
27         Details = scan(var1,-1,'-');
28         drop var var1;
29                 OUTPUT;
30              END;
31         RUN;

NOTE: The variable file_names exists on an input data set, but was also specified in an I/O statement option.  The variable will 
      not be included on any output data set.
NOTE: The infile IN is:
      Filename=/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-30_tmptcmlva2_19142.log,
      
      File List=('/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-30_tmptcmlva2_19142.log' 
      '/apps/tir/test/loganalysis/
'),
      Owner Name=sassrv,Group Name=sas,
      Access Permission=rwxrwxr-x,
      Last Modified=Mon Aug 31 00:01:56 2015,
      File Size (bytes)=720559

NOTE: The infile IN is:
      Filename=/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-29_tmptcmlva2_19142.log,
      
      File List=('/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-29_tmptcmlva2_19142.log' 
      '/apps/tir/test/loganalysis/
'),
      Owner Name=sassrv,Group Name=sas,
      Access Permission=rwxrwxr-x,
      Last Modified=Sun Aug 30 00:01:46 2015,
      File Size (bytes)=720559

NOTE: The infile IN is:
      Filename=/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-28_tmptcmlva2_19142.log,
      
      File List=('/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-08-28_tmptcmlva2_19142.log' 
      '/apps/tir/test/loganalysis/
'),
      Owner Name=sassrv,Group Name=sas,
      Access Permission=rwxrwxr-x,
      Last Modified=Sat Aug 29 00:01:36 2015,
      File Size (bytes)=2815408

NOTE: 1 record was read from the infile IN.
      The minimum record length was 572.
      The maximum record length was 572.
NOTE: 1 record was read from the infile IN.
      The minimum record length was 572.
      The maximum record length was 572.
&amp;#12;3                                                          The SAS System                           08:36 Friday, September 11, 2015

NOTE: 1 record was read from the infile IN.
      The minimum record length was 572.
      The maximum record length was 572.
NOTE: There were 3 observations read from the data set WORK.DIRLIST.
NOTE: The data set WORK.OUTPUT_DATA_SET has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.00 seconds
      &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 13:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/225153#M40399</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2015-09-11T13:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a list of files and conditionally export the files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/225339#M40432</link>
      <description>&lt;P&gt;I'm looking for some guidance to complete this task. Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 06:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-list-of-files-and-conditionally-export-the-files/m-p/225339#M40432</guid>
      <dc:creator>RamKumar</dc:creator>
      <dc:date>2015-09-14T06:34:56Z</dc:date>
    </item>
  </channel>
</rss>

