<?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 files without spaces in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235628#M43130</link>
    <description>&lt;P&gt;Simple compress() function should suffice here (note updated as didn't see three variable requirement first time round):&lt;/P&gt;
&lt;PRE&gt;data want (drop=line);
  infile datalines;
  length prod_code $3 msrp 8 holidayprice 8 line $200;
  input line $;
  prod_code=compress(line," .","d");
  line=compress(line," ","a");
  msrp=input(substr(line,1,index(line,".")+2),best.);
  holidayprice=input(substr(line,index(line,".")+2),best.);
datalines;
ACR7.957.80
MGI4.754.00
BLD112.25109.75
CFP9.659.25
MAL8.258.10
CM45.9045.30
AZC1.991.93
CMW20.0019.00
AMZ2.702.30
GAC52.0050.25
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Nov 2015 09:34:39 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-11-20T09:34:39Z</dc:date>
    <item>
      <title>Reading raw data files without spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235615#M43128</link>
      <description>&lt;P&gt;ACR7.957.80&lt;BR /&gt;MGI4.754.00&lt;BR /&gt;BLD112.25109.75&lt;BR /&gt;CFP9.659.25&lt;BR /&gt;MAL8.258.10&lt;BR /&gt;CM45.9045.30&lt;BR /&gt;AZC1.991.93&lt;BR /&gt;CMW20.0019.00&lt;BR /&gt;AMZ2.702.30&lt;BR /&gt;GAC52.0050.25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello All - I am a novice in SAS trying to get my hands wet with coding. Above is the data from my notepad which i was to convert into a SAS dataset. First 3 letters go into &amp;nbsp;var= &amp;nbsp;Prod.code (line 6 has only CM, just 2 letters), two numbers with 2 decimals each follow. The first 2 decimal # &amp;nbsp;goes under "msrp" variable and the following 2 decimal # under "holidayprice".&lt;/P&gt;&lt;P&gt;Please provide some directions/leads on how to approach this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&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>Fri, 20 Nov 2015 06:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235615#M43128</guid>
      <dc:creator>nk_sas</dc:creator>
      <dc:date>2015-11-20T06:10:56Z</dc:date>
    </item>
    <item>
      <title>Betreff: Reading raw data files without spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235626#M43129</link>
      <description>&lt;P&gt;Using a regular expression can solve the task. Have a look at the functions prxparse, prxmatch and prxposn.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data work.want;

   length 
      ProdCode $ 3 mrsp holidayprice 8
      _rx 8
   ;

   format mrsp holidayprice 10.2;

   retain _rx;
   drop _rx;

   if _n_ = 1 then do;
      _rx = prxparse('/([A-Z]+)(\d+\.\d\d)(\d+\.\d\d)/');
   end;

   input;

   if prxmatch(_rx, strip(_infile_)) then do;
      ProdCode = prxposn(_rx, 1, strip(_infile_));
      mrsp = input(prxposn(_rx, 2, strip(_infile_)), best32.);
      holidayprice = input(prxposn(_rx, 3, strip(_infile_)), best32.);
   end;

   datalines;
ACR7.957.80
MGI4.754.00
BLD112.25109.75
CFP9.659.25
MAL8.258.10
CM45.9045.30
AZC1.991.93
CMW20.0019.00
AMZ2.702.30
GAC52.0050.25
;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Nov 2015 09:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235626#M43129</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2015-11-20T09:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data files without spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235628#M43130</link>
      <description>&lt;P&gt;Simple compress() function should suffice here (note updated as didn't see three variable requirement first time round):&lt;/P&gt;
&lt;PRE&gt;data want (drop=line);
  infile datalines;
  length prod_code $3 msrp 8 holidayprice 8 line $200;
  input line $;
  prod_code=compress(line," .","d");
  line=compress(line," ","a");
  msrp=input(substr(line,1,index(line,".")+2),best.);
  holidayprice=input(substr(line,index(line,".")+2),best.);
datalines;
ACR7.957.80
MGI4.754.00
BLD112.25109.75
CFP9.659.25
MAL8.258.10
CM45.9045.30
AZC1.991.93
CMW20.0019.00
AMZ2.702.30
GAC52.0050.25
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2015 09:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235628#M43130</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-11-20T09:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data files without spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235629#M43131</link>
      <description>&lt;P&gt;Since you data does not contain any field delimiters you need to apply your&amp;nbsp;own rules that could separate the three data values from each other:&lt;/P&gt;&lt;P&gt;* Before the first&amp;nbsp;nonalphabetic character (use e.g. the NOTALPHA function to find that position)&lt;/P&gt;&lt;P&gt;* Two positions after the first decimal period (use e.g. the INDEX function to find that position)&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/900iF02BB2E3EFF3EEC6/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Skärmklipp.PNG" title="Skärmklipp.PNG" width="171" height="71" /&gt;&lt;/P&gt;&lt;P&gt;Then you can create your three variables by e.g. using the SUBSTR function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2015 09:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235629#M43131</guid>
      <dc:creator>Rikard</dc:creator>
      <dc:date>2015-11-20T09:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data files without spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235803#M43151</link>
      <description>&lt;P&gt;You've got already good answers of how to read your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In case what you've posted is all you need to read into SAS and not only a small subset of your real data then what I would do is manually shape your data in Notepad into a form which is easy to read with SAS (eg. the values you want separated by comma).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2015 23:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235803#M43151</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-20T23:30:49Z</dc:date>
    </item>
    <item>
      <title>Betreff: Reading raw data files without spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235813#M43152</link>
      <description>&lt;P&gt;Thank you for the reply. You've introduced me to new functions to deal with such a task. On the same lines, what kinds of suggestions would you give me to do well at coding in SAS. The kind of approach i need (i dont have computer science background).&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 02:25:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235813#M43152</guid>
      <dc:creator>nk_sas</dc:creator>
      <dc:date>2015-11-21T02:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data files without spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235814#M43153</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you for the reply. The logic you provided is good to gain deeper understanding on usual concepts. On the same lines, what kinds of suggestions would you give me to do well at coding in SAS. The kind of approach i need (i dont have computer science background).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 02:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235814#M43153</guid>
      <dc:creator>nk_sas</dc:creator>
      <dc:date>2015-11-21T02:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data files without spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235815#M43154</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you for the reply. All answers provided here - along with yours have shown me how i should think. On the same lines, what kinds of suggestions would you give me to do well at coding in SAS. The kind of approach i need (i dont have computer science background).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 02:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235815#M43154</guid>
      <dc:creator>nk_sas</dc:creator>
      <dc:date>2015-11-21T02:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data files without spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235816#M43155</link>
      <description>&lt;P&gt;Hi Patrick - I am quite okay to code for reading flat files with delimiters. To learn more I wanted to check what if there are no such dlm in the data and how to deal in such situations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 02:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-files-without-spaces/m-p/235816#M43155</guid>
      <dc:creator>nk_sas</dc:creator>
      <dc:date>2015-11-21T02:36:57Z</dc:date>
    </item>
  </channel>
</rss>

