<?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 raw data from an external files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/427978#M105606</link>
    <description>&lt;P&gt;Its not a good idea to post your email address to an open website, so its removed now.&amp;nbsp; With regards to your questions I would do things in two steps:&lt;/P&gt;
&lt;P&gt;1) Read in the first datafile which contains the metadata for the second.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Using the data read in from step 1, generate the code needed to read in the second.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now as I don't have much to go on, this just shows and example:&lt;/P&gt;
&lt;PRE&gt;data meta;
  infile "metadata.txt" dlm=",";
  length name format $200;
  input name $ format $;
run;

data _null_;
  set meta end=last;
  if _n_=1 then call execute('data want; infile "rawdata.txt" dlm=","; input ');
  call execute(name," ",format);
  if last then call execute(';run;');
run;&lt;/PRE&gt;
&lt;P&gt;This will create the code for data want, based on the information read in from the first datastep.&amp;nbsp; Note that this is an advanced topic, so if you only learning it would be far simpler for you to program a plain datastep which reads in the second file manually based on the spec provided rather than try to generate code from it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jan 2018 11:46:53 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-01-16T11:46:53Z</dc:date>
    <item>
      <title>Reading raw data from an external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/427974#M105603</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am Tasin. I have a query related to external raw files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Query:- &lt;SPAN&gt;There are two external raw files. 1st file contains only the descriptor portion (Heading only) and 2nd raw file contains only data portion. How can we combined these two file into single file using data step&amp;nbsp;or SQL.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;I am trying to expalin the query below.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;There are two external raw files (.txt).&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;File1.txt&lt;/STRONG&gt; =&amp;nbsp; It contains &lt;STRONG&gt;only Descriptor portion&lt;/STRONG&gt; (Column Name)&lt;/DIV&gt;
&lt;DIV&gt;ex- EmpId Name&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;File2.txt&lt;/STRONG&gt; = It contains &lt;STRONG&gt;only Data portion&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;ex-&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;101 Tasin&lt;/DIV&gt;
&lt;DIV&gt;102&amp;nbsp;Andy&lt;/DIV&gt;
&lt;DIV&gt;103 Ted&lt;/DIV&gt;
&lt;DIV&gt;104&amp;nbsp;Mikael&lt;/DIV&gt;
&lt;DIV&gt;105&amp;nbsp;Senastien&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Now we have to combined these two extenal raw data into single dataset.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;output :-&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;EmpId Name&lt;/DIV&gt;
&lt;DIV&gt;101&amp;nbsp; &amp;nbsp;Tasin&lt;/DIV&gt;
&lt;DIV&gt;102&amp;nbsp; &amp;nbsp;Vijay&lt;/DIV&gt;
&lt;DIV&gt;103&amp;nbsp; &amp;nbsp;Arul&lt;/DIV&gt;
&lt;DIV&gt;104&amp;nbsp; &amp;nbsp;Arvind&lt;/DIV&gt;
&lt;DIV&gt;105&amp;nbsp; &amp;nbsp;Malaye&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;-------------------------------------------------------&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;I tried with data step as shown below.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Data Combine;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;infile " path File2.txt";&amp;nbsp; /* This file contains data portion only so NO PROBLEM*/&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;input EmpID Name$;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* Here we write normally variables name manually. Here need to read variables from RAW File1, which contains only variables*/&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Problem is in INPUT statement. So here, we need to think only on INPUT statement that how can we fetch the columns from FILE1?&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Please help me. My Email id =&amp;nbsp;&amp;lt;redacted&amp;gt;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 Jan 2018 11:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/427974#M105603</guid>
      <dc:creator>Tasin_Ahmed</dc:creator>
      <dc:date>2018-01-16T11:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from an external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/427977#M105605</link>
      <description>&lt;P&gt;Since file1 contains no meta-information (type, size, format) for the columns, you will still need to write that manually, so there's no sense in trying to automate that.&lt;/P&gt;
&lt;P&gt;If you simply concatenate the two files externally and use proc import, this would come closest to an automated solution. But be aware that the results of proc import are not consistent and therefore not suitable for a long-time solution.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 11:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/427977#M105605</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-16T11:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from an external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/427978#M105606</link>
      <description>&lt;P&gt;Its not a good idea to post your email address to an open website, so its removed now.&amp;nbsp; With regards to your questions I would do things in two steps:&lt;/P&gt;
&lt;P&gt;1) Read in the first datafile which contains the metadata for the second.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Using the data read in from step 1, generate the code needed to read in the second.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now as I don't have much to go on, this just shows and example:&lt;/P&gt;
&lt;PRE&gt;data meta;
  infile "metadata.txt" dlm=",";
  length name format $200;
  input name $ format $;
run;

data _null_;
  set meta end=last;
  if _n_=1 then call execute('data want; infile "rawdata.txt" dlm=","; input ');
  call execute(name," ",format);
  if last then call execute(';run;');
run;&lt;/PRE&gt;
&lt;P&gt;This will create the code for data want, based on the information read in from the first datastep.&amp;nbsp; Note that this is an advanced topic, so if you only learning it would be far simpler for you to program a plain datastep which reads in the second file manually based on the spec provided rather than try to generate code from it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 11:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/427978#M105606</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-16T11:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from an external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/427988#M105612</link>
      <description>&lt;P&gt;Since the file with the column names does not have any information on the type of variable to read, I suggest to combine the two files into one and use Proc IMPORT to do the rest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Combining the file into one, there are several possibilities depending your operating system and the size of the files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See below an example using a DATA Step to combine the files and Proc IMPORT the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename xdata ("c:\temp\data_meta.txt" "c:\temp\data_data.txt");
filename xout temp;

data _null_;
  infile xdata;
  input;
  file xout;
  put _infile_;
run;

proc import file=xout out=want dbms=csv replace;
  delimiter=" ";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 12:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/427988#M105612</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2018-01-16T12:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from an external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/428002#M105618</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Since the file with the column names does not have any information on the type of variable to read, I suggest to combine the two files into one and use Proc IMPORT to do the rest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Combining the file into one, there are several possibilities depending your operating system and the size of the files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See below an example using a DATA Step to combine the files and Proc IMPORT the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename xdata ("c:\temp\data_meta.txt" "c:\temp\data_data.txt");
filename xout temp;

data _null_;
  infile xdata;
  input;
  file xout;
  put _infile_;
run;

proc import file=xout out=want dbms=csv replace;
  delimiter=" ";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The only reason that you needed to copy the lines from the fileref XDATA to the temporary file XOUT is because PROC IMPORT is unable to properly read the header records from the fileref XDATA.&lt;/P&gt;
&lt;P&gt;Why does PROC IMPORT not handle the aggregate fileref properly?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 13:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/428002#M105618</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-01-16T13:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from an external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/428007#M105619</link>
      <description>&lt;P&gt;Why Proc Import can not handle the XDATA fileref, I have no idea. This is a question for Technical Support.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 14:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-an-external-files/m-p/428007#M105619</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2018-01-16T14:10:19Z</dc:date>
    </item>
  </channel>
</rss>

