<?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 in data--special characters trigger new line in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-data-special-characters-trigger-new-line/m-p/908135#M358418</link>
    <description>&lt;P&gt;Does below return what you're after?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let external_file=%sysfunc(pathname(work))\mysource.txt;
data _null_;
  file "&amp;amp;external_file";
  infile datalines truncover;
  input;
  put _infile_;
  datalines;
cat dog ~ mouse cat rat*
cat
snake
*
dog
bat
rat~cat~
;

data want;
  infile "&amp;amp;external_file" dlm='*~' recfm=N lrecl=256;
  input var :$256.;
  /* replace CR and LF with a blank */
  var=prxchange('s/[\n\r]+/ /',-1,strip(var));
  if missing(var) then delete;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1702606543080.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/91432i089C0AC2103233A8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1702606543080.png" alt="Patrick_0-1702606543080.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Dec 2023 02:15:50 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-12-15T02:15:50Z</dc:date>
    <item>
      <title>Reading in data--special characters trigger new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-data-special-characters-trigger-new-line/m-p/908121#M358410</link>
      <description>&lt;P&gt;I have data in a txt file. I'm trying to figure out how to specify that a special character (or multiple characters) signify the end of a line of data. In the example below, the ~ and the * are the characters which signify that the row of data is complete and it's time for a new row. The data set HAVE is how I'm currently reading the data in. The data set WANT is how I want it to look.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data HAVE;
infile datalines truncover;
input line $500.;
datalines ;
cat dog ~ mouse cat rat*
cat
snake
*
dog
bat
rat~cat~
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WANT&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cat dog ~&lt;BR /&gt;2 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mouse cat rat*&lt;BR /&gt;3 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cat snake*&lt;BR /&gt;4 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dog bat rat~&lt;BR /&gt;5 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cat~&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible? Thanks in advance for any help.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 22:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-data-special-characters-trigger-new-line/m-p/908121#M358410</guid>
      <dc:creator>edoyle1</dc:creator>
      <dc:date>2023-12-14T22:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in data--special characters trigger new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-data-special-characters-trigger-new-line/m-p/908127#M358414</link>
      <description>&lt;P&gt;Do you only want it to have meaning if it is the last character on the line?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if it appears in the middle of a line?&amp;nbsp; Does this line still mean the end?&amp;nbsp; Or do you want to ignore those?&amp;nbsp; Or do you also want to split one line into multiple lines?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to read from a TEXT file? Or do you already have the data in dataset?&lt;/P&gt;
&lt;P&gt;In either case are you trying to generate a new text file or a new dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only at the end is much easier.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 length line $500;
 do until(indexc('*~',char(line,length(line))));
   set have;
   length newline $2000 ;
   newline=catx(' ',newline,line);
 end;
 drop line;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    newline

 1     cat dog ~ mouse cat rat*
 2     cat snake *
 3     dog bat rat~cat~
&lt;/PRE&gt;
&lt;P&gt;Otherwise perhaps you can just reprocess the new line back into individual lines.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 length line $2000;
 do until(indexc('*~',char(line,length(line))));
   set have;
   length newline $2000 ;
   newline=catx(' ',newline,line);
 end;
 do index=1 to countw(newline,'~*')-1;
   line=scan(newline,index,'~*');
   output;
 end;
 drop newline index;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    line

 1     cat dog
 2      mouse cat rat
 3     cat snake
 4     dog bat rat
 5     cat
&lt;/PRE&gt;
&lt;P&gt;Notice the space at the start of the new line two.&lt;/P&gt;
&lt;P&gt;Do you want that?&amp;nbsp; If not add a LEFT() function around the SCAN() function to remove the leading spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 22:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-data-special-characters-trigger-new-line/m-p/908127#M358414</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-14T22:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in data--special characters trigger new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-data-special-characters-trigger-new-line/m-p/908135#M358418</link>
      <description>&lt;P&gt;Does below return what you're after?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let external_file=%sysfunc(pathname(work))\mysource.txt;
data _null_;
  file "&amp;amp;external_file";
  infile datalines truncover;
  input;
  put _infile_;
  datalines;
cat dog ~ mouse cat rat*
cat
snake
*
dog
bat
rat~cat~
;

data want;
  infile "&amp;amp;external_file" dlm='*~' recfm=N lrecl=256;
  input var :$256.;
  /* replace CR and LF with a blank */
  var=prxchange('s/[\n\r]+/ /',-1,strip(var));
  if missing(var) then delete;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1702606543080.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/91432i089C0AC2103233A8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1702606543080.png" alt="Patrick_0-1702606543080.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 02:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-data-special-characters-trigger-new-line/m-p/908135#M358418</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-15T02:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in data--special characters trigger new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-data-special-characters-trigger-new-line/m-p/908223#M358454</link>
      <description>That did it, thanks!</description>
      <pubDate>Fri, 15 Dec 2023 15:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-data-special-characters-trigger-new-line/m-p/908223#M358454</guid>
      <dc:creator>edoyle1</dc:creator>
      <dc:date>2023-12-15T15:47:46Z</dc:date>
    </item>
  </channel>
</rss>

