<?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 know the source of  multiple infile files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/know-the-source-of-multiple-infile-files/m-p/289270#M59740</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have more than one external files to be infiled into SAS,but&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to know which record comes from which different one of the four files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;quarter1.dat&lt;BR /&gt;1 120321 1236 154669 211326&lt;BR /&gt;1 326264 1326 163354 312665&lt;BR /&gt;1 420698 1327 142336 422685&lt;BR /&gt;1 211368 1236 156327 655237&lt;BR /&gt;1 378596 1429 145678 366578&lt;/P&gt;
&lt;P&gt;quarter2.dat&lt;BR /&gt;2 140362 1436 114641 362415&lt;BR /&gt;2 157956 1327 124869 345215&lt;BR /&gt;2 215547 1472 165578 412567&lt;BR /&gt;2 204782 1495 150479 364474&lt;BR /&gt;2 232571 1345 135467 332567&lt;/P&gt;
&lt;P&gt;quarter3.dat&lt;BR /&gt;3 140357 1339 142693 205881&lt;BR /&gt;3 149964 1420 152367 223795&lt;BR /&gt;3 159852 1479 160001 254874&lt;BR /&gt;3 139957 1527 163567 263088&lt;BR /&gt;A&amp;nbsp;150047 1602 175561 277552&lt;/P&gt;
&lt;P&gt;quarter4.dat&lt;BR /&gt;4 479574 1367 155997 36134&lt;BR /&gt;4 496207 1459 140396 35941&lt;BR /&gt;4 501156 1598 135489 39640&lt;BR /&gt;4 532982 1601 143269 38695&lt;BR /&gt;4 563222 1625 147889 39556&lt;BR /&gt;filename year ('d:\quarter1.dat' 'd:\quarter2.dat' 'd:\quarter3.dat' 'd:\quarter4.dat');&lt;BR /&gt;data temp;&lt;BR /&gt;infile year;&lt;BR /&gt;input quarter sales tax expenses payroll;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That means I want there will be a new&amp;nbsp;&amp;nbsp;flag variable can tell me&amp;nbsp;"A 150047 1602 175561 277552" comes from quarter 3.(don't modify the external files)&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;I hope there was some code like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;filename year ('d:\quarter1.dat'(in=a) 'd:\quarter2.dat'(in=b) 'd:\quarter3.dat'(in=c) 'd:\quarter4.dat'(in=d));&lt;/P&gt;
&lt;P&gt;data temp;&lt;BR /&gt;infile year;&lt;BR /&gt;input quarter sales tax expenses payroll;&lt;/P&gt;
&lt;P&gt;if a then flag=1;&lt;/P&gt;
&lt;P&gt;if&amp;nbsp;b then flag=2;&lt;/P&gt;
&lt;P&gt;if&amp;nbsp;c then flag=3;&lt;/P&gt;
&lt;P&gt;if&amp;nbsp;d then flag=4;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 03 Aug 2016 15:55:25 GMT</pubDate>
    <dc:creator>GeorgeSAS</dc:creator>
    <dc:date>2016-08-03T15:55:25Z</dc:date>
    <item>
      <title>know the source of  multiple infile files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/know-the-source-of-multiple-infile-files/m-p/289270#M59740</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have more than one external files to be infiled into SAS,but&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to know which record comes from which different one of the four files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;quarter1.dat&lt;BR /&gt;1 120321 1236 154669 211326&lt;BR /&gt;1 326264 1326 163354 312665&lt;BR /&gt;1 420698 1327 142336 422685&lt;BR /&gt;1 211368 1236 156327 655237&lt;BR /&gt;1 378596 1429 145678 366578&lt;/P&gt;
&lt;P&gt;quarter2.dat&lt;BR /&gt;2 140362 1436 114641 362415&lt;BR /&gt;2 157956 1327 124869 345215&lt;BR /&gt;2 215547 1472 165578 412567&lt;BR /&gt;2 204782 1495 150479 364474&lt;BR /&gt;2 232571 1345 135467 332567&lt;/P&gt;
&lt;P&gt;quarter3.dat&lt;BR /&gt;3 140357 1339 142693 205881&lt;BR /&gt;3 149964 1420 152367 223795&lt;BR /&gt;3 159852 1479 160001 254874&lt;BR /&gt;3 139957 1527 163567 263088&lt;BR /&gt;A&amp;nbsp;150047 1602 175561 277552&lt;/P&gt;
&lt;P&gt;quarter4.dat&lt;BR /&gt;4 479574 1367 155997 36134&lt;BR /&gt;4 496207 1459 140396 35941&lt;BR /&gt;4 501156 1598 135489 39640&lt;BR /&gt;4 532982 1601 143269 38695&lt;BR /&gt;4 563222 1625 147889 39556&lt;BR /&gt;filename year ('d:\quarter1.dat' 'd:\quarter2.dat' 'd:\quarter3.dat' 'd:\quarter4.dat');&lt;BR /&gt;data temp;&lt;BR /&gt;infile year;&lt;BR /&gt;input quarter sales tax expenses payroll;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That means I want there will be a new&amp;nbsp;&amp;nbsp;flag variable can tell me&amp;nbsp;"A 150047 1602 175561 277552" comes from quarter 3.(don't modify the external files)&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;I hope there was some code like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;filename year ('d:\quarter1.dat'(in=a) 'd:\quarter2.dat'(in=b) 'd:\quarter3.dat'(in=c) 'd:\quarter4.dat'(in=d));&lt;/P&gt;
&lt;P&gt;data temp;&lt;BR /&gt;infile year;&lt;BR /&gt;input quarter sales tax expenses payroll;&lt;/P&gt;
&lt;P&gt;if a then flag=1;&lt;/P&gt;
&lt;P&gt;if&amp;nbsp;b then flag=2;&lt;/P&gt;
&lt;P&gt;if&amp;nbsp;c then flag=3;&lt;/P&gt;
&lt;P&gt;if&amp;nbsp;d then flag=4;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 15:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/know-the-source-of-multiple-infile-files/m-p/289270#M59740</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2016-08-03T15:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: know the source of  multiple infile files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/know-the-source-of-multiple-infile-files/m-p/289293#M59749</link>
      <description>&lt;P&gt;The INFILE statement has a FILEVAR option that stores the filename.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Infile .... Filevar=filevar;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;source=FILEVAR;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*rest of SAS code...&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 17:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/know-the-source-of-multiple-infile-files/m-p/289293#M59749</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-03T17:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: know the source of  multiple infile files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/know-the-source-of-multiple-infile-files/m-p/289294#M59750</link>
      <description>&lt;P&gt;Don't think there is a way of doing it out of box upon your existing code, however, if you can put your file names in the cards/dataline/dataset, here is one way (not tested, may need tweak):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile datalines;
   length fileloc $ 300;
   input fileloc $ ; /* read instream data       */
  /* The INFILE statement closes the current file 
     and opens a new one if FILELOC changes value 
     when INFILE executes                        */
   infile dummy filevar=fileloc 
          end=done; 
  /* DONE set to 1 when last input record read  */
   do while(not done);
  /* Read all input records from the currently  */
  /* opened input file, write to want       */
     input var1-var5;
     source=fileloc;
   output;
   end;
     
   datalines;
d:\quarter1.dat
d:\quarter2.dat
d:\quarter3.dat
d:\quarter4.dat
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;'Souce' field will contain the incoming file information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 17:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/know-the-source-of-multiple-infile-files/m-p/289294#M59750</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-08-03T17:20:22Z</dc:date>
    </item>
  </channel>
</rss>

