<?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: Creating a dataset by reading files with different variables in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476570#M30944</link>
    <description>&lt;P&gt;Read both with the same datastep, and use the truncover option with the infile. Variables not present in the first half will be set to missing.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jul 2018 19:11:49 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-07-09T19:11:49Z</dc:date>
    <item>
      <title>Creating a dataset by reading files with different variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476558#M30942</link>
      <description>&lt;P&gt;I have to create a macro where txt or fixed width files from a folder has to read in with sas and a universal dataset is to be created.&lt;/P&gt;&lt;P&gt;But the first half has 46 variable and 2nd half has 48 variables. How to put into one dataset?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 18:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476558#M30942</guid>
      <dc:creator>rshrv</dc:creator>
      <dc:date>2018-07-09T18:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset by reading files with different variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476570#M30944</link>
      <description>&lt;P&gt;Read both with the same datastep, and use the truncover option with the infile. Variables not present in the first half will be set to missing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 19:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476570#M30944</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-09T19:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset by reading files with different variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476577#M30945</link>
      <description>&lt;P&gt;And you don't need a macro to import all files, you can use * in the infile-statement to read all files in a directory.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 19:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476577#M30945</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2018-07-09T19:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset by reading files with different variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476595#M30946</link>
      <description>&lt;P&gt;That depends, are you trying to make the file wide (add columns to make a really wide file) or append them together?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a fixed width file you have no choice but to write a data step code to read it in.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For other files you can try with PROC IMPORT, though you’re likely to run into compatibility issues with types, ie read a file as character when its numeric in another and then when you try and append them you’ll run into issues.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So first, figure out how many different file types you have, then how you want to combine them. If you can explain that process to us, we can better recommend a solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variables are mostly the same and you’re appending to make a long file, it’s a bit easier of a process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220071"&gt;@rshrv&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have to create a macro where txt or fixed width files from a folder has to read in with sas and a universal dataset is to be created.&lt;/P&gt;
&lt;P&gt;But the first half has 46 variable and 2nd half has 48 variables. How to put into one dataset?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 20:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476595#M30946</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-09T20:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset by reading files with different variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476800#M30953</link>
      <description>&lt;P&gt;So, I have different folders that contain more than 300 files: Some folders have tab delimited and some have fixed width.&lt;/P&gt;&lt;P&gt;Suppose file 1 has&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;jane&amp;nbsp; 45 4RT&amp;nbsp; M&lt;/P&gt;&lt;P&gt;john 23 4GJT M&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file2:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;george 23 3DFE&amp;nbsp; &amp;nbsp; &amp;nbsp; 1J M&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;jake&amp;nbsp; &amp;nbsp; &amp;nbsp;54 4KL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1K M&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to append File 1 and file 2 where I want to add 4th column which shows null for file 1 but 1J, 1K for file 2.&lt;/P&gt;&lt;P&gt;My codes looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;infile " path* " delimiter = '09'x MISSOVER DSD;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;informat&amp;nbsp;&lt;/P&gt;&lt;P&gt;name $10.&lt;/P&gt;&lt;P&gt;age 2.&lt;/P&gt;&lt;P&gt;res_num $7.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;idnum $2.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;gender $1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format&amp;nbsp;&lt;/P&gt;&lt;P&gt;name $10.&lt;/P&gt;&lt;P&gt;age 2.&lt;/P&gt;&lt;P&gt;res_num $7.&lt;/P&gt;&lt;P&gt;idnum $2.&lt;/P&gt;&lt;P&gt;gender $1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input&lt;/P&gt;&lt;P&gt;name $10.&lt;/P&gt;&lt;P&gt;age 2.&lt;/P&gt;&lt;P&gt;res_num $7.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;idnum $2.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;gender $1.&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I run this, there's no separate column created instead the 5 column is copied and breaks further column's data.&lt;/P&gt;&lt;P&gt;How should I approach this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 13:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476800#M30953</guid>
      <dc:creator>rshrv</dc:creator>
      <dc:date>2018-07-10T13:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset by reading files with different variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476804#M30954</link>
      <description>&lt;P&gt;It did not work. Data of length of n-1 field appears in Nth field.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 13:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476804#M30954</guid>
      <dc:creator>rshrv</dc:creator>
      <dc:date>2018-07-10T13:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset by reading files with different variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476809#M30955</link>
      <description>&lt;P&gt;For delimited files, do not use informats in the input statement. You already specified them in the informat statement.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 13:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476809#M30955</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-10T13:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset by reading files with different variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476814#M30957</link>
      <description>&lt;P&gt;You might be able to make a program smart enough to read both file formats.&lt;/P&gt;
&lt;P&gt;First define ALL of the variables.&amp;nbsp; Just attaching a format or an informat to variable will only DEFINE the variable as a side effect.&amp;nbsp; None of the variables in your example need to have either formats or informats attached to them. SAS knows how to read and write simple numbers and character strings.&amp;nbsp; Normally you only need to add formats and informats for date and time variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length name $10 age 8 res_num $7 idnum $2 gender $1 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the line is designed to be fixed width then read it using formatted input.&amp;nbsp; If it is delimited by tabs then read it using list mode. This is actually a good example of why you should be using the newer (less than 30 years old) TRUNCOVER option instead of the older less useful MISSOVER option.&amp;nbsp; When you read with list mode it makes no difference, but in formatted mode it can cause short values to be set to missing.&lt;/P&gt;
&lt;P&gt;How can you tell which files have the fifth variable? Let's assume that the tab delimited files have the fifth variable and the fixed format files do not.&lt;/P&gt;
&lt;P&gt;So something like this to read the lines conditionally might work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  infile "filename" dsd dlm='09'x truncover ;
  input @;
  if index(_infile_,'09'x) then input name age res_num  idnum gender ;
  else input name $10. age 2. res_num $7. gender $1. ;
&lt;/CODE&gt;&lt;/PRE&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>Tue, 10 Jul 2018 13:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-a-dataset-by-reading-files-with-different-variables/m-p/476814#M30957</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-10T13:53:08Z</dc:date>
    </item>
  </channel>
</rss>

