<?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: Confirmation about below behaviour of Infile in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484049#M125600</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/219515"&gt;@shahsn11&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that i can create one more table and then used it to append it to Table1. But do we have a option in Infile like we have in Proc Import (replace is the option i am talking about).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As you probably know, omitting the REPLACE option of PROC IMPORT is just a protection against overwriting an existing dataset. It does &lt;EM&gt;not&lt;/EM&gt; provide for automated appending. If you need this type of protection, have a look at the &lt;A href="http://documentation.sas.com/?docsetId=ledsoptsref&amp;amp;docsetTarget=p1f10d520qrhren14k1wo8sjjmb7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;REPLACE=&lt;/A&gt; dataset option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is possible to read two or more CSV files in the same data step (see examples in the &lt;A href="http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;documentation&lt;/A&gt; of the INFILE statement). But for just two files I don't think it's worth the coding effort (as PROC APPEND is so easy to use). If the second CSV file was not yet available when the first one is processed, this wouldn't work anyway. Also,&amp;nbsp;it's safer to read the (possibly small) second file separately and append&amp;nbsp;the resulting dataset to the (possibly large and valuable) cumulative dataset only after checking it carefully.&lt;/P&gt;</description>
    <pubDate>Sat, 04 Aug 2018 19:24:02 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2018-08-04T19:24:02Z</dc:date>
    <item>
      <title>Confirmation about below behaviour of Infile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484034#M125594</link>
      <description>&lt;P&gt;I used infile to read a CSV and store its information in a particular table , lets say Table1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i used another CSV file and try to store its information in the same table. Every time the old content in table Table1 is deleted and new one is inserted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way i can append the content of 2 different files into same table Tablel1 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that i can create one more table and then used it to append it to Table1. But do we have a option in Infile like we have in Proc Import (replace is the option i am talking about).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 17:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484034#M125594</guid>
      <dc:creator>shahsn11</dc:creator>
      <dc:date>2018-08-04T17:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Confirmation about below behaviour of Infile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484035#M125595</link>
      <description>&lt;P&gt;Read into a temporary table and then append that to the first one.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 18:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484035#M125595</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-04T18:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Confirmation about below behaviour of Infile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484042#M125597</link>
      <description>&lt;P&gt;It can be done, but will probably take longer than using the approach that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;suggested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Create examples of the two files */

data _null_;
  infile datalines truncover;
  file "/folders/myfolders/base_file.csv" dsd;
  input id fruit :$10.;
  put (_all_) (+1);
  datalines;
1 apple
2 banana
3 coconut
;
run;

data _null_;
  infile datalines truncover;
  file "/folders/myfolders/append_it.csv" dsd;
  input id fruit :$10.;
  put (_all_) (+1);
  datalines;
4 date
5 elderberry
6 fig
;
run;

/* create first dataset */
data have;
  infile '/folders/myfolders/base_file.csv' dsd;
  input id fruit :$10.;
run;

/* append second dataset */
data have;
  set have end=last;
  infile '/folders/myfolders/append_it.csv' dsd end=lastnew;
  output;
  if last then do until (lastnew);
    input id fruit :$10.;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 22:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484042#M125597</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-08-04T22:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Confirmation about below behaviour of Infile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484049#M125600</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/219515"&gt;@shahsn11&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that i can create one more table and then used it to append it to Table1. But do we have a option in Infile like we have in Proc Import (replace is the option i am talking about).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As you probably know, omitting the REPLACE option of PROC IMPORT is just a protection against overwriting an existing dataset. It does &lt;EM&gt;not&lt;/EM&gt; provide for automated appending. If you need this type of protection, have a look at the &lt;A href="http://documentation.sas.com/?docsetId=ledsoptsref&amp;amp;docsetTarget=p1f10d520qrhren14k1wo8sjjmb7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;REPLACE=&lt;/A&gt; dataset option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is possible to read two or more CSV files in the same data step (see examples in the &lt;A href="http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;documentation&lt;/A&gt; of the INFILE statement). But for just two files I don't think it's worth the coding effort (as PROC APPEND is so easy to use). If the second CSV file was not yet available when the first one is processed, this wouldn't work anyway. Also,&amp;nbsp;it's safer to read the (possibly small) second file separately and append&amp;nbsp;the resulting dataset to the (possibly large and valuable) cumulative dataset only after checking it carefully.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 19:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484049#M125600</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-08-04T19:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Confirmation about below behaviour of Infile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484065#M125602</link>
      <description>&lt;P&gt;Please show what code you are using.&lt;/P&gt;
&lt;P&gt;Here is an example of doing what you asked.&amp;nbsp; First let's make a new datasets and at the same time create a CSV file we want to read in and append to it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv temp;
data file1 ;
 set sashelp.class ;
 file csv dsd ;
 put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now FILE1 has a copy of SASHELP.CLASS and the filename CSV points to another copy in a comma delimited text file.&lt;/P&gt;
&lt;P&gt;Now that I have created a test situation that is similar to your request I can show you how to use a data step that uses the MODIFY command and INFILE to append new observations to FILE1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data file1 ;
  modify file1 ;
  infile csv dsd truncover ;
  input (_all_) (+0);
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 21:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484065#M125602</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-04T21:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Confirmation about below behaviour of Infile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484067#M125603</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/219515"&gt;@shahsn11&lt;/a&gt;: While I definitely like the look of&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s suggested code over that which I suggested, I should point out that both sets of code do the same thing, but my code runs 76 times faster than&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;: I was actually trying to see how much faster your code would be and was surprised to see that it ran so much slower. Any idea why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The test I ran was:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create examples of the two files */

data _null_;
  infile datalines truncover;
  file "/folders/myfolders/base_file.csv" dsd;
  input id fruit :$10.;
  do i=1 to 100000;
    put (_all_) (+1);
  end;
  datalines;
1 apple
2 banana
3 coconut
;
run;

data _null_;
  infile datalines truncover;
  file "/folders/myfolders/append_it.csv" dsd;
  input id fruit :$10.;
  do i=1 to 100000;
    put (_all_) (+1);
  end;
  datalines;
4 date
5 elderberry
6 fig
;
run;

/* create first dataset */
data have;
  infile '/folders/myfolders/base_file.csv' dsd;
  input id fruit :$10.;
run;

data want1;
  set have;
run;

/* append second dataset */
data want1 ;
  modify want1 ;
  infile "/folders/myfolders/append_it.csv" dsd truncover ;
  input (_all_) (+0);
  output;
run;

data want2;
  set have end=last;
  infile '/folders/myfolders/append_it.csv' dsd end=lastnew;
  output;
  if last then do until (lastnew);
    input id fruit :$10.;
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 22:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484067#M125603</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-08-04T22:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Confirmation about below behaviour of Infile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484070#M125606</link>
      <description>&lt;P&gt;Executing the MODIFY statement on every data step iteration causes extra processing time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it turns out you don't have to actually execute it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* MODIFY */
data want1 ;
  if 0 then modify want1 ;
  infile extra dsd truncover ;
  input (_all_) (+0);
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Aug 2018 22:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484070#M125606</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-04T22:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Confirmation about below behaviour of Infile</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484072#M125608</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Still takes twice as long, but a definite improvement!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 23:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Confirmation-about-below-behaviour-of-Infile/m-p/484072#M125608</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-08-04T23:27:35Z</dc:date>
    </item>
  </channel>
</rss>

