<?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: Importing Ascii file with fixed column but inconsistent delimiters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-Ascii-file-with-fixed-column-but-inconsistent/m-p/69439#M15066</link>
    <description>Melissa,&lt;BR /&gt;
It appears you actually have space delimited text file, not a fixed-column file.  Change the data step to use LIST input, and it should go well.&lt;BR /&gt;
&lt;BR /&gt;
In the INFILE section, change the data step from:&lt;BR /&gt;
&lt;BR /&gt;
Data &amp;amp;data_data;&lt;BR /&gt;
INFILE &amp;amp;data firstobs=14;&lt;BR /&gt;
INPUT Var1 1-7 Var2 10-18 Var3 20-28;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
to:&lt;BR /&gt;
&lt;BR /&gt;
Data &amp;amp;data_data;&lt;BR /&gt;
INFILE &amp;amp;data firstobs=14;&lt;BR /&gt;
INPUT Var1 Var2 Var3;&lt;BR /&gt;
RUN;</description>
    <pubDate>Wed, 25 May 2011 20:19:46 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2011-05-25T20:19:46Z</dc:date>
    <item>
      <title>Importing Ascii file with fixed column but inconsistent delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Ascii-file-with-fixed-column-but-inconsistent/m-p/69438#M15065</link>
      <description>Dear All,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to establish a macro to import ascii files that have fixed columns but they have inconsistent number of a space delimiter. I am far to any success. My data looks like this;&lt;BR /&gt;
&lt;BR /&gt;
291.91   7.01      49.92&lt;BR /&gt;
293.28   8.59      55.92&lt;BR /&gt;
294.67   8.58      62.58&lt;BR /&gt;
296.08   10.98     68.24&lt;BR /&gt;
297.49   11.13     73.68&lt;BR /&gt;
298.92   10.98     80.24&lt;BR /&gt;
300.37   14.35     101.75&lt;BR /&gt;
301.82   22.59     142.68&lt;BR /&gt;
303.29   28.95     195.66&lt;BR /&gt;
304.77   32.23     251.02&lt;BR /&gt;
1099.91  -510.07   850.12&lt;BR /&gt;
1102.76  511.29    766.93&lt;BR /&gt;
1105.66  0.00      348.10&lt;BR /&gt;
1108.60  625.03    1250.06&lt;BR /&gt;
1111.58  541.22    -631.42&lt;BR /&gt;
1114.60  -854.57   854.57&lt;BR /&gt;
1117.67  774.13    290.30&lt;BR /&gt;
1120.78  302.89    201.93&lt;BR /&gt;
1123.94  -209.54   314.31&lt;BR /&gt;
1127.15  -211.53   317.29 &lt;BR /&gt;
&lt;BR /&gt;
or &lt;BR /&gt;
&lt;BR /&gt;
1102.76  119981.68 234509.66&lt;BR /&gt;
1105.66  126010.92 245059.90&lt;BR /&gt;
1108.60  115005.43 247154.52&lt;BR /&gt;
1111.58  126284.38 228033.50&lt;BR /&gt;
1114.60  118500.25 238519.74&lt;BR /&gt;
1117.67  116893.37 233786.74&lt;BR /&gt;
1120.78  121965.48 247161.83&lt;BR /&gt;
1123.94  112313.59 238037.76&lt;BR /&gt;
1127.15  119300.86 216602.97&lt;BR /&gt;
1130.40  116193.22 254344.21&lt;BR /&gt;
&lt;BR /&gt;
The code that I have been trying are;&lt;BR /&gt;
&lt;BR /&gt;
1) INFILE&lt;BR /&gt;
&lt;BR /&gt;
%macro Import (Dir=, WorkFile=);    &lt;BR /&gt;
  *PROC PRINTTO log = '&lt;DIR&gt;&lt;FILENAME&gt;';  &lt;BR /&gt;
 PROC SQL noprint;                                                                                                                      &lt;BR /&gt;
  select file into :dfile                                                                                                               &lt;BR /&gt;
  separated by ' '                                                                                                                      &lt;BR /&gt;
  from Dir_Ref;                                                                                                                         &lt;BR /&gt;
 RUN;                                                                                                                                   &lt;BR /&gt;
   %let k=1;                                                                                                                            &lt;BR /&gt;
   %let data = %scan(&amp;amp;dfile, &amp;amp;k);                                                                                                       &lt;BR /&gt;
   *%let ext = .txt; &lt;BR /&gt;
  %do %while("&amp;amp;data" NE "");                                                                                                            &lt;BR /&gt;
filename &amp;amp;data "&amp;amp;Dir&amp;amp;data";&lt;BR /&gt;
Data &amp;amp;data_data;&lt;BR /&gt;
INFILE &amp;amp;data firstobs=14;&lt;BR /&gt;
INPUT Var1 1-7 Var2 10-18 Var3 20-28;&lt;BR /&gt;
RUN;&lt;BR /&gt;
	%let k = %eval(&amp;amp;k + 1);                                                                                                              &lt;BR /&gt;
   %let data = %scan(&amp;amp;dfile, &amp;amp;k); &lt;BR /&gt;
  %end;                                                                                                                                 &lt;BR /&gt;
  ;                                                                                                                                     &lt;BR /&gt;
  RUN; &lt;BR /&gt;
  PROC PRINTTO; RUN;&lt;BR /&gt;
&lt;BR /&gt;
2) PROC IMPORT&lt;BR /&gt;
&lt;BR /&gt;
%macro Import (Dir=, WorkFile=);    &lt;BR /&gt;
  *PROC PRINTTO log = '&lt;DIR&gt;&lt;FILENAME&gt;';  &lt;BR /&gt;
 PROC SQL noprint;                                                                                                                      &lt;BR /&gt;
  select file into :dfile                                                                                                               &lt;BR /&gt;
  separated by ' '                                                                                                                      &lt;BR /&gt;
  from Dir_Ref;                                                                                                                         &lt;BR /&gt;
 RUN;                                                                                                                                   &lt;BR /&gt;
   %let k=1;                                                                                                                            &lt;BR /&gt;
   %let data = %scan(&amp;amp;dfile, &amp;amp;k);                                                                                                       &lt;BR /&gt;
   *%let ext = .txt; &lt;BR /&gt;
  %do %while("&amp;amp;data" NE "");                                                                                                            &lt;BR /&gt;
    PROC IMPORT                                                                                                                         &lt;BR /&gt;
     datafile ="&amp;amp;Dir&amp;amp;data"&lt;BR /&gt;
	 out= &amp;amp;data                                                                                                                         &lt;BR /&gt;
       dbms= dlm                                                                                                                        &lt;BR /&gt;
     replace;                                                                                                                           &lt;BR /&gt;
       delimiter='      ' ;                                                                                                                   &lt;BR /&gt;
     getnames=NO; GUESSINGROWS=14 to 526                                                                                                                      &lt;BR /&gt;
    RUN;                                                                                                                                    &lt;BR /&gt;
   %let k = %eval(&amp;amp;k + 1);                                                                                                              &lt;BR /&gt;
   %let data = %scan(&amp;amp;dfile, &amp;amp;k); &lt;BR /&gt;
  %end;                                                                                                                                 &lt;BR /&gt;
  ;                                                                                                                                     &lt;BR /&gt;
  RUN; &lt;BR /&gt;
  PROC PRINTTO; RUN;&lt;BR /&gt;
%mend Import;    &lt;BR /&gt;
&lt;BR /&gt;
Your assistances are deeply appreciated. Many thanks.&lt;/FILENAME&gt;&lt;/DIR&gt;&lt;/FILENAME&gt;&lt;/DIR&gt;</description>
      <pubDate>Wed, 25 May 2011 17:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Ascii-file-with-fixed-column-but-inconsistent/m-p/69438#M15065</guid>
      <dc:creator>MelissaMuharam</dc:creator>
      <dc:date>2011-05-25T17:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Ascii file with fixed column but inconsistent delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Ascii-file-with-fixed-column-but-inconsistent/m-p/69439#M15066</link>
      <description>Melissa,&lt;BR /&gt;
It appears you actually have space delimited text file, not a fixed-column file.  Change the data step to use LIST input, and it should go well.&lt;BR /&gt;
&lt;BR /&gt;
In the INFILE section, change the data step from:&lt;BR /&gt;
&lt;BR /&gt;
Data &amp;amp;data_data;&lt;BR /&gt;
INFILE &amp;amp;data firstobs=14;&lt;BR /&gt;
INPUT Var1 1-7 Var2 10-18 Var3 20-28;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
to:&lt;BR /&gt;
&lt;BR /&gt;
Data &amp;amp;data_data;&lt;BR /&gt;
INFILE &amp;amp;data firstobs=14;&lt;BR /&gt;
INPUT Var1 Var2 Var3;&lt;BR /&gt;
RUN;</description>
      <pubDate>Wed, 25 May 2011 20:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Ascii-file-with-fixed-column-but-inconsistent/m-p/69439#M15066</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-05-25T20:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Ascii file with fixed column but inconsistent delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Ascii-file-with-fixed-column-but-inconsistent/m-p/69440#M15067</link>
      <description>Dear SASJedi,&lt;BR /&gt;
&lt;BR /&gt;
It seems that when I copied and pasted the data, it didn't do any justice to the original data file. It is actually looks like this,&lt;BR /&gt;
&lt;BR /&gt;
291.91   -0.04     1.00 &lt;BR /&gt;
(3 spaces between column 1 and 2, and 5 spaces between column 2 and 3)&lt;BR /&gt;
&lt;BR /&gt;
293.28   -0.07     0.09 &lt;BR /&gt;
(3 spaces between column 1 and 2, and 5 spaces between column 2 and 3)&lt;BR /&gt;
&lt;BR /&gt;
294.67   0.13      0.15 &lt;BR /&gt;
(3 spaces between column 1 and 2, and 6 spaces between column 2 and 3)&lt;BR /&gt;
&lt;BR /&gt;
296.08   0.00      0.23 &lt;BR /&gt;
(3 spaces between column 1 and 2, and 6 spaces between column 2 and 3)&lt;BR /&gt;
&lt;BR /&gt;
1037.67  336.14    -126.05 &lt;BR /&gt;
(2 spaces between column 1 and 2, and 4 spaces between column 2 and 3)&lt;BR /&gt;
&lt;BR /&gt;
1097.09  -1134.11  243.02 &lt;BR /&gt;
(2 spaces between column 1 and 2, and 2 spaces between column 2 and 3)&lt;BR /&gt;
&lt;BR /&gt;
However, the column number seems fixed for each column (1 to 7, 10 to 18 and 20 - 28). I also have tried your suggestion, but it didn't work as well. Your assistance is really appreciated.</description>
      <pubDate>Thu, 26 May 2011 15:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Ascii-file-with-fixed-column-but-inconsistent/m-p/69440#M15067</guid>
      <dc:creator>MelissaMuharam</dc:creator>
      <dc:date>2011-05-26T15:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Ascii file with fixed column but inconsistent delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-Ascii-file-with-fixed-column-but-inconsistent/m-p/69441#M15068</link>
      <description>Melissa,&lt;BR /&gt;
&lt;BR /&gt;
The following test code executes without issue on SAS9.2 under Windows 7:&lt;BR /&gt;
&lt;BR /&gt;
*Begin code ****************************************************;&lt;BR /&gt;
/* Create a text file to experiment with */&lt;BR /&gt;
filename textfile 'c:\temp\test.txt';&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   file textfile;&lt;BR /&gt;
   if _n_=1 then do i=1 to 13;&lt;BR /&gt;
     PUT "Do not read this";&lt;BR /&gt;
   end;&lt;BR /&gt;
   input;&lt;BR /&gt;
   put _infile_;&lt;BR /&gt;
datalines;&lt;BR /&gt;
291.91   -0.04     1.00 &lt;BR /&gt;
293.28   -0.07     0.09 &lt;BR /&gt;
294.67   0.13      0.15 &lt;BR /&gt;
296.08   0.00      0.23 &lt;BR /&gt;
1037.67  336.14    -126.05 &lt;BR /&gt;
1097.09  -1134.11  243.02 &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Data test;&lt;BR /&gt;
INFILE textfile firstobs=14;&lt;BR /&gt;
INPUT Var1 Var2 Var3;&lt;BR /&gt;
RUN; &lt;BR /&gt;
proc print; run;&lt;BR /&gt;
*End code ****************************************************;&lt;BR /&gt;
OUTPUT:&lt;BR /&gt;
Obs Var1       Var2     Var3 &lt;BR /&gt;
1     291.91      -0.04       1.00 &lt;BR /&gt;
2     293.28      -0.07       0.09 &lt;BR /&gt;
3     294.67       0.13       0.15 &lt;BR /&gt;
4     296.08       0.00       0.23 &lt;BR /&gt;
5    1037.67   336.14  -126.05 &lt;BR /&gt;
6    1097.09  -1134.11  243.02 &lt;BR /&gt;
&lt;BR /&gt;
The Data _NULL_ step correctly re-created the text just as you described it to me, (I checked it out in UltraEdit) and the second Data step read it in without a hitch using list input.  &lt;BR /&gt;
&lt;BR /&gt;
Please specify exactly what problem you are experiencing.  It would also be useful to have a small sample of the exact text that is NOT reading in correctly, along with an example of how it looks in SAS, so we can further diagnose the problem.&lt;BR /&gt;
&lt;BR /&gt;
Stay SASy!&lt;BR /&gt;
SASJedi</description>
      <pubDate>Thu, 26 May 2011 18:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-Ascii-file-with-fixed-column-but-inconsistent/m-p/69441#M15068</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-05-26T18:52:51Z</dc:date>
    </item>
  </channel>
</rss>

