<?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: Combining two text files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/311641#M67418</link>
    <description>&lt;P&gt;Using them as column headers makes no sense, as you can't change your dataset structure halfway through the data step.&lt;/P&gt;
&lt;P&gt;Instead you define the columns with the input statement, and you best simply discard those lines:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile in truncover;
input x1 $ x2 $;
if upcase(substr(x1,1,1)) ne 'X';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only had to read one file, using firstobs=2 in the infile statement will also do the trick.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2016 10:22:44 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-11-15T10:22:44Z</dc:date>
    <item>
      <title>Combining two text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/310981#M67100</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two text files. Each of them has a continuous numeric variable (the same variable across both, ContVar); one of them also has a categorical var. Basically, I want to create a format in which all values of ContVar in either text file are valid values for Var1 in my SAS dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Textfile 1&lt;/P&gt;&lt;P&gt;ContVar&amp;nbsp;&amp;nbsp; CategVar&lt;/P&gt;&lt;P&gt;12345&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abc&lt;/P&gt;&lt;P&gt;23456&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def&lt;/P&gt;&lt;P&gt;34567&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ghi&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Textfile 2&lt;/P&gt;&lt;P&gt;Contvar&lt;/P&gt;&lt;P&gt;890123&lt;/P&gt;&lt;P&gt;874321&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know the simple but inefficient way to do this (1. Create SAS dataset from textfile 1, 2. Create SAS dataset from textfile2, 3. Stack them and then create the format file). I'm hoping there is a more efficient way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I thought I only needed the values from Textfile 1, this is the formatting step I came up with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want (keep=start label hlo fmtname);&lt;/P&gt;&lt;P&gt;infile "path/Textfile1.txt" end=eof;&lt;/P&gt;&lt;P&gt;input start CategVar $;&lt;/P&gt;&lt;P&gt;retain fmtname '$fmt_name';&lt;/P&gt;&lt;P&gt;retain label 'VALID';&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;if eof;&lt;/P&gt;&lt;P&gt;start=' ';&lt;/P&gt;&lt;P&gt;label='NOT VALID';&lt;/P&gt;&lt;P&gt;hlo='O';&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format cntlin=want;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm hoping Textfile 2 can just somehow be incorporated into that (or similar) rather than the process I outlined above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2016 14:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/310981#M67100</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2016-11-11T14:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/310982#M67101</link>
      <description>&lt;P&gt;You can combine multiple filenames in a filename statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename in ('$HOME/test1.txt','$HOME/test2.txt');
data test;
infile in truncover;
input x1 $ x2 $;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2016 14:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/310982#M67101</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-11T14:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/311627#M67407</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this solution and it didn't work. I've attached the 2 text files that I used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Book 1 has&amp;nbsp;2 columns (x1 and y) and Book 2 and 1 column (x2)&lt;/P&gt;
&lt;P&gt;Data gets stacked but all X1 and Y are combined&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;filename&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; in (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'C:\stageAreasSas\textImport\Book1.txt'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'C:\stageAreasSas\textImport\Book2.txt'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;infile&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; in &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;truncover&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; x1 $ x2 $;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 09:22:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/311627#M67407</guid>
      <dc:creator>tgalliga</dc:creator>
      <dc:date>2016-11-15T09:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/311630#M67410</link>
      <description>&lt;P&gt;Since Book1.txt is delimited with a comma (and Book2.txt only has one column), use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile in dlm=',' truncover;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2016 09:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/311630#M67410</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-15T09:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/311633#M67413</link>
      <description>&lt;P&gt;Thanks,that works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried it with tab separated initially but that didn't work so I when to csv. now working wiht the dlm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quick question.&lt;/P&gt;
&lt;P&gt;the column names are imported as rows. do you know how to tell the import that they are column headers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;T&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13142i357EAB7B6EAE7840/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Import.PNG" title="Import.PNG" /&gt;</description>
      <pubDate>Tue, 15 Nov 2016 10:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/311633#M67413</guid>
      <dc:creator>tgalliga</dc:creator>
      <dc:date>2016-11-15T10:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/311641#M67418</link>
      <description>&lt;P&gt;Using them as column headers makes no sense, as you can't change your dataset structure halfway through the data step.&lt;/P&gt;
&lt;P&gt;Instead you define the columns with the input statement, and you best simply discard those lines:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile in truncover;
input x1 $ x2 $;
if upcase(substr(x1,1,1)) ne 'X';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only had to read one file, using firstobs=2 in the infile statement will also do the trick.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 10:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-text-files/m-p/311641#M67418</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-15T10:22:44Z</dc:date>
    </item>
  </channel>
</rss>

