<?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 Reading Text File + PRXCHANGE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767588#M243374</link>
    <description>&lt;P&gt;I'm reading a text file with INFILE in a DATA step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get the right text, the right content, with the right length&amp;nbsp;(checked with LENGHT)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The TRIMmed string length is equal to the length of the not trimmed string&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I pass the string to PRXCHANGE -- the regex fails, no match&lt;/P&gt;
&lt;P&gt;When I pass the TRIMmed string to PRXCHANGE, it works -- the regex find the match correctly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm doing this ina a SAS Studio Virtual Lab&lt;/P&gt;
&lt;P&gt;I created the file with the VL first as a SAS file, and then I renamed it with extension TXT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The same happens when I use DATALINES instead of a physical file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll appreciate your help, thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;---&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt; data tmp (keep=xx);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; infile fp delimiter=' ';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; retain parsed;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; length xx 6.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; input;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; row= _infile_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; if _N_=1 then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; parsed= prxparse(" ...the regex expression...");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; row= _infile_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; xx= prxchange(parsed,1,trim(row)); /* it works */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; xx= prxchange(parsed,1,trim(row)); /* it doesn't work */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Sep 2021 00:29:53 GMT</pubDate>
    <dc:creator>hernan_AR</dc:creator>
    <dc:date>2021-09-14T00:29:53Z</dc:date>
    <item>
      <title>Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767588#M243374</link>
      <description>&lt;P&gt;I'm reading a text file with INFILE in a DATA step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get the right text, the right content, with the right length&amp;nbsp;(checked with LENGHT)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The TRIMmed string length is equal to the length of the not trimmed string&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I pass the string to PRXCHANGE -- the regex fails, no match&lt;/P&gt;
&lt;P&gt;When I pass the TRIMmed string to PRXCHANGE, it works -- the regex find the match correctly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm doing this ina a SAS Studio Virtual Lab&lt;/P&gt;
&lt;P&gt;I created the file with the VL first as a SAS file, and then I renamed it with extension TXT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The same happens when I use DATALINES instead of a physical file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll appreciate your help, thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;---&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt; data tmp (keep=xx);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; infile fp delimiter=' ';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; retain parsed;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; length xx 6.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; input;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; row= _infile_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; if _N_=1 then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; parsed= prxparse(" ...the regex expression...");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; row= _infile_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; xx= prxchange(parsed,1,trim(row)); /* it works */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; xx= prxchange(parsed,1,trim(row)); /* it doesn't work */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 00:29:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767588#M243374</guid>
      <dc:creator>hernan_AR</dc:creator>
      <dc:date>2021-09-14T00:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767592#M243377</link>
      <description>&lt;P&gt;I don't understand what the question is.&lt;/P&gt;
&lt;P&gt;SAS has two types of variables, floating point numbers and fixed length character strings.&lt;/P&gt;
&lt;P&gt;If you want to use regular expression against character variables you will always have to account for possibility of spaces that might be added to pad the string to the fixed length of the variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either remove the spaces by using a function like TRIM() , TRIMN(), STRIP(), CATS() , etc.&lt;/P&gt;
&lt;P&gt;Or by including check for 0 or more trailing spaces in the pattern of your REGEX.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 01:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767592#M243377</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-14T01:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767593#M243378</link>
      <description>&lt;P&gt;Note that the LENGTH() function by definition ignores trailing spaces.&amp;nbsp; So the value calculated by LENGTH() is not a good test of whether or not the value has trailing spaces.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 01:07:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767593#M243378</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-14T01:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767604#M243382</link>
      <description>&lt;P&gt;Does your RegEx check for end of string?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, these 2 are the exact same:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    xx= prxchange(parsed,1,trim(row)); /* it works */
    xx= prxchange(parsed,1,trim(row)); /* it doesn't work */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 03:05:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767604#M243382</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-09-14T03:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767675#M243418</link>
      <description>Ok, thanks, &lt;BR /&gt;but the crazy thing is that LENGTH gives me the actual number of bytes&lt;BR /&gt;(computed by selecting the line with Notepad++)&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Sep 2021 12:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767675#M243418</guid>
      <dc:creator>hernan_AR</dc:creator>
      <dc:date>2021-09-14T12:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767676#M243419</link>
      <description>Yes, thanks, I put it that way just for you to know what works and what doesn't</description>
      <pubDate>Tue, 14 Sep 2021 12:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767676#M243419</guid>
      <dc:creator>hernan_AR</dc:creator>
      <dc:date>2021-09-14T12:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767678#M243420</link>
      <description>&lt;P&gt;Oh, you're right, I forgot to clarify my question, my question is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;why do I need to TRIM the string read&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;considering that the string read from the file is identical to the line content&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;and that the length of the string read is equal to the actual length of the line?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;is there something hidden, like an enconding problem&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;or a different data type needed for PRXCHANGE?&lt;/STRONG&gt;&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, 14 Sep 2021 12:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767678#M243420</guid>
      <dc:creator>hernan_AR</dc:creator>
      <dc:date>2021-09-14T12:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767680#M243421</link>
      <description>&lt;P&gt;this is the regex&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;s/(^.*)(&lt;STRONG&gt;SomeAlphaNumPrefix&lt;/STRONG&gt;)(&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;[\d]+&lt;/FONT&gt;&lt;/STRONG&gt;)(\.sas7bdat)$/$3/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with this, I get the digits between the prefix and the extension to the end&lt;/P&gt;
&lt;P&gt;because I just need the digits, discarding the rest&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do you see anything wrong here ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 12:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767680#M243421</guid>
      <dc:creator>hernan_AR</dc:creator>
      <dc:date>2021-09-14T12:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767682#M243423</link>
      <description>&lt;P&gt;SAS uses &lt;STRONG&gt;FIXED&lt;/STRONG&gt; length character variables.&amp;nbsp; Short values are always padded with spaces to the full length of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure how you think your two identical statements are generating different results.&amp;nbsp; Perhaps you meant to say that using the special _INFILE_ syntax behaves differently than using a real variable?&amp;nbsp; That might be possible as SAS might treat _INFILE_ differently than a normal variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't tell SAS how to define a variable it will guess and set the definition at the first place in your code where it need to have it set.&amp;nbsp; So if the first place you reference ROW is in the assignment statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ROW = _INFILE_ ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then ROW will be defined as character with a length that matches the LRECL (logical record length) of the FILE being read.&amp;nbsp; If you are using in-line data (CARDS aka DATALINES) then that is always a multiple of 80.&amp;nbsp; If you are using an external file then default value for LRECL is now 32767 although for older versions of SAS it as 256.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you actually want to know how many characters are one the line you have read from the file use the INFILE option LENGTH= to define a variable that will hold that informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you wanted to create a SAS dataset that could be used to re-create a variable length text file you might use something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data text ;
   infile 'myfile.txt' length=ll truncover ;
   input line $char256. ;
   line_length = ll ;
   last_non_blank = lengthn(line);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then use that dataset to re-create the file including the right number of trailing spaces by using the $VARYING format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set text;
  file 'newfile.txt';
  put line $varying256. line_length ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 12:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767682#M243423</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-14T12:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767683#M243424</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393693"&gt;@hernan_AR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;this is the regex&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;s/(^.*)(&lt;STRONG&gt;SomeAlphaNumPrefix&lt;/STRONG&gt;)(&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;[\d]+&lt;/FONT&gt;&lt;/STRONG&gt;)(\.sas7bdat)$/$3/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with this, I get the digits between the prefix and the extension to the end&lt;/P&gt;
&lt;P&gt;because I just need the digits, discarding the rest&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do you see anything wrong here ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes. The pattern is NOT accounting for the trailing spaces that will be padded onto a fixed length variable so that its length matches the defined length of the variable.&amp;nbsp; You could for example do something like:&lt;/P&gt;
&lt;PRE&gt;s/(^.*)(SomeAlphaNumPrefix)([\d]+)(\.sas7bdat\ *)$/$3/&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 12:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767683#M243424</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-14T12:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767684#M243425</link>
      <description>$ means end of string. If you don't trim you have spaces at the end as I said, so you can't match this expression.</description>
      <pubDate>Tue, 14 Sep 2021 12:41:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767684#M243425</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-09-14T12:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767698#M243430</link>
      <description>&lt;P&gt;I'm seeing now that the problem is that I supposed that SAS get the line as it is on the file&lt;/P&gt;
&lt;P&gt;but&amp;nbsp; SAS seems to put the content in holder variable of length 32767 bytes ( I used LENGTHC )&lt;/P&gt;
&lt;P&gt;the result is that the variable read has many trailing blanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm new in SAS, I didn't know that mechanism&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tested with $varying100 but this fills with blanks up to 100 bytes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; infile datalines delimiter=' ' length=lx;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; format row $varying100. lx;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there any way to get just the bytes, as they are in the file?&lt;/P&gt;
&lt;P&gt;I mean, like a standard "readline"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;this code demonstrates the problem&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data tmp (keep=xx);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; infile datalines delimiter=' ';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; retain parsed;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; input;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; row= _infile_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; if _N_=1 then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; parsed= prxparse("s/(^.*)(prefix)([\d]+)(.sas7bdat)$/$3/");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; xx= prxchange(parsed,1,TRIM(row));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; l1= lengthC("prefix20210914.sas7bdat");&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; l2= lengthC(row);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; putlog l1=;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; putlog l2=;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; datalines;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;prefix20210903.sas7bdat&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;prefix20210829.sas7bdat&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;prefix20210914.sas7bdat&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&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, 14 Sep 2021 13:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767698#M243430</guid>
      <dc:creator>hernan_AR</dc:creator>
      <dc:date>2021-09-14T13:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767729#M243432</link>
      <description>&lt;P&gt;Use the number of bytes in the line to control how many of the bytes stored in the variable you pass onto the next step in your processing.&amp;nbsp; Note that using in-line data (aka CARDS or DATALINES) will result in fixed length records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's create a variable length file with your lines of text:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options parmcards=example;
filename example temp;
parmcards;
prefix20210903.sas7bdat
prefix20210829.sas7bdat
prefix20210914.sas7bdat
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And read from that file and try different ways of removing the trailing spaces from the value passed to the REGEX function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data variable;
  if _N_=1 then do;
      parsed= prxparse("s/(^.*)(prefix)([\d]+)(.sas7bdat)$/$3/");
      retain parsed;
  end;
  infile example length=line_length truncover;
  length row x1-x3 $100 ;
  input;
  row = _infile_;
  putlog _n_= line_length= row= :$quote.;
  x1= prxchange(parsed,1,row);
  x2= prxchange(parsed,1,TRIM(row));
  x3= prxchange(parsed,1,substrn(row,1,line_length));
  putlog (x1-x3) (=:$quote. /);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you check the values written to the log you can see that the lines are all the same 23 bytes long, but the variable ROW is always 100 bytes long because that is how it was defined with the LENGTH statement.&lt;/P&gt;
&lt;PRE&gt;_N_=1 line_length=23 row="prefix20210903.sas7bdat"
x1="prefix20210903.sas7bdat"
x2="20210903"
x3="20210903"
_N_=2 line_length=23 row="prefix20210829.sas7bdat"
x1="prefix20210829.sas7bdat"
x2="20210829"
x3="20210829"
_N_=3 line_length=23 row="prefix20210914.sas7bdat"
x1="prefix20210914.sas7bdat"
x2="20210914"
x3="20210914"
&lt;/PRE&gt;
&lt;P&gt;If we modify the code to use in-line data instead you will see that the lines are all 80 bytes long.&amp;nbsp; So in that case the SUBSTRN() function will return a different string than the TRIM() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fixed ;
  if _N_=1 then do;
      parsed= prxparse("s/(^.*)(prefix)([\d]+)(.sas7bdat)$/$3/");
      retain parsed;
  end;
  infile cards length=line_length truncover;
  length row x1-x3 $100 ;
  input;
  row = _infile_;
  putlog _n_= line_length= row= :$quote.;
  x1= prxchange(parsed,1,row);
  x2= prxchange(parsed,1,TRIM(row));
  x3= prxchange(parsed,1,substrn(row,1,line_length));
  putlog (x1-x3) (=:$quote. /);
cards;
prefix20210903.sas7bdat
prefix20210829.sas7bdat
prefix20210914.sas7bdat
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log messages:&lt;/P&gt;
&lt;PRE&gt;_N_=1 line_length=80 row="prefix20210903.sas7bdat"
x1="prefix20210903.sas7bdat"
x2="20210903"
x3="prefix20210903.sas7bdat"
_N_=2 line_length=80 row="prefix20210829.sas7bdat"
x1="prefix20210829.sas7bdat"
x2="20210829"
x3="prefix20210829.sas7bdat"
_N_=3 line_length=80 row="prefix20210914.sas7bdat"
x1="prefix20210914.sas7bdat"
x2="20210914"
x3="prefix20210914.sas7bdat"
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note:&amp;nbsp;&amp;nbsp;The FORMAT of a variable has nothing to do with how the variable is DEFINED.&lt;STRONG&gt; A FORMAT converts values to text and an INFORMAT converts text to values.&lt;/STRONG&gt;&amp;nbsp;The FORMAT statement just updates the metadata that says what (if any) special format you want to use as the default format to use when displaying the variable.&amp;nbsp;&amp;nbsp;You cannot use the $VARYING format with FORMAT statement.&amp;nbsp; &amp;nbsp;When you go to display the value there will be no way for you pass in the required second variable that contains the number of characters you actually want to display in this instance.&amp;nbsp; Use the $VARYING format only in PUT statements and the $VARYING informat only in INPUT statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the Insert Code or Insert SAS Code icons on the editor bar to get a pop-up window to paste/edit your included text and/or SAS program lines.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:21:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767729#M243432</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-14T14:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767731#M243433</link>
      <description>&lt;P&gt;I've just read the code you posted, I'm sorry, I was writing my last post before reading your's&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I changed some lines, as you suggested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; infile datalines delimiter=' ' truncover length=lx;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; input row $varying100. lx;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &lt;EM&gt;*row= _infile_; previous commented out statement&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but variable "row" ends having a length of 100, I mean the length is not variable&lt;/P&gt;
&lt;P&gt;I'm confused...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767731#M243433</guid>
      <dc:creator>hernan_AR</dc:creator>
      <dc:date>2021-09-14T14:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767733#M243434</link>
      <description>&lt;P&gt;INFORMATS convert text to values.&amp;nbsp; They have nothing to do with how the variable is DEFINED.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have not defined the variable before you reference it then SAS will guess that you want to define the length of the variable based on the information at hand. So if you are using a INFORMAT with the variable in that statement then it will guess that it should set the length of the variable to match the width of the informat you are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What varies with the $VARYING informat is how many bytes to read from the input line.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767733#M243434</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-14T14:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767736#M243436</link>
      <description>&lt;P&gt;Note if you want the last word in a line use the SCAN() function with -1 as the index.&amp;nbsp; Much easier (and faster) then REGEX.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;extension = scan(row,-1,'.');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767736#M243436</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-14T14:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767737#M243437</link>
      <description>&lt;P&gt;The actual data has more than 80 bytes&lt;/P&gt;
&lt;P&gt;So, according to your comments, I need to TRIM always in order to get it into work&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no problem with doing a TRIM&lt;/P&gt;
&lt;P&gt;I'm new in SAS, I thought that it would work like a "ReadLine()" function in other languages&lt;/P&gt;
&lt;P&gt;reading the entire line up to the line feed or CR character&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767737#M243437</guid>
      <dc:creator>hernan_AR</dc:creator>
      <dc:date>2021-09-14T14:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767738#M243438</link>
      <description>&lt;P&gt;The _INFILE_ automatic variable is exactly line the READLINE() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is the variable that you are assigning the results into that is different.&amp;nbsp; Other languages have variable types that support varying length strings.&amp;nbsp; So the system is recording somehow that this value of ROW is only 23 bytes long and the value on the next observation is 27 bytes long.&amp;nbsp; SAS has no way to do that.&amp;nbsp; If you want to do it then store that information yourself into some other variable.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767738#M243438</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-14T14:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text File + PRXCHANGE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767744#M243439</link>
      <description>&lt;P&gt;oh, good to know it&lt;/P&gt;
&lt;P&gt;that's why communities llike this are great!&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text-File-PRXCHANGE/m-p/767744#M243439</guid>
      <dc:creator>hernan_AR</dc:creator>
      <dc:date>2021-09-14T14:48:44Z</dc:date>
    </item>
  </channel>
</rss>

