<?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 Strip values from a varchar field and add carriage return? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835486#M330305</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable in my dataset that I need to scrub.&amp;nbsp; The data has special characters that need to be scrubbed out and a carriage return added to make it appear like a list in the variable field.&amp;nbsp; This data will be pulled into a spreadsheet this way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example the values could look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Old Data&lt;BR /&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;Corporate (ABC);#1;#Little Rock Branch;#21&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;Iowa Office;#5;#Des Moines (FCO);#44&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;New Data&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;
&lt;P&gt;Corporate (ABC)&lt;/P&gt;
&lt;P&gt;Little Rock Branch&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;
&lt;P&gt;Iowa Office&lt;/P&gt;
&lt;P&gt;Des Moines (FCO)&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am hoping there might be a function that can handle this.&amp;nbsp; Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Sep 2022 19:27:01 GMT</pubDate>
    <dc:creator>elwayfan446</dc:creator>
    <dc:date>2022-09-27T19:27:01Z</dc:date>
    <item>
      <title>Strip values from a varchar field and add carriage return?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835486#M330305</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable in my dataset that I need to scrub.&amp;nbsp; The data has special characters that need to be scrubbed out and a carriage return added to make it appear like a list in the variable field.&amp;nbsp; This data will be pulled into a spreadsheet this way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example the values could look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Old Data&lt;BR /&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;Corporate (ABC);#1;#Little Rock Branch;#21&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;Iowa Office;#5;#Des Moines (FCO);#44&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;New Data&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;
&lt;P&gt;Corporate (ABC)&lt;/P&gt;
&lt;P&gt;Little Rock Branch&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;
&lt;P&gt;Iowa Office&lt;/P&gt;
&lt;P&gt;Des Moines (FCO)&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am hoping there might be a function that can handle this.&amp;nbsp; Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 19:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835486#M330305</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2022-09-27T19:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Strip values from a varchar field and add carriage return?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835489#M330306</link>
      <description>&lt;P&gt;Looks like the strings are using the two byte sequence ;# as the delimiter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And your examples make it look like you just want to keep every other item from the delimited list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length copy new_data $200 ;
  copy=tranwrd(old_data,';#','01'x);
  do index=1 by 2 to countw(copy,'01'x,'m');
     new_data=catx('0d'x,new_data,scan(copy,index,'01'x,'m'));
  end;
  drop copy index ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But is not clear why you think inserting a carriage return character will make it look like multiple lines. How are you LOOKing at the values?&amp;nbsp; &amp;nbsp;If you are generating standard old text listing files then PROC REPORT will honor the SPLIT= option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  row+1;
  length old_data $200;
  input;
  old_data=_infile_;
cards4;
Corporate (ABC);#1;#Little Rock Branch;#21
Iowa Office;#5;#Des Moines (FCO);#44
;;;;

data want;
  set have;
  length copy new_data $200 ;
  copy=tranwrd(old_data,';#','01'x);
  do index=1 by 2 to countw(copy,'01'x,'m');
     new_data=catx('|',new_data,scan(copy,index,'01'x,'m'));
  end;
  drop copy index ;
run;

proc report data=want split='|';
  column row new_data ;
  define row / order ;
  define new_data / width=100 flow ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;        row  new_data
          1  Corporate (ABC)
             Little Rock Branch
          2  Iowa Office
             Des Moines (FCO)
&lt;/PRE&gt;
&lt;P&gt;But someone that is better at getting ODS to do anything useful will need explain how you could create print-outs using ODS that honor you line breaks.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 19:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835489#M330306</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-27T19:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Strip values from a varchar field and add carriage return?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835493#M330310</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data old;
input string $ 1 - 50;
datalines4;
Corporate (ABC);#1;#Little Rock Branch;#21 
Iowa Office;#5;#Des Moines (FCO);#44       
;;;;

data new(keep = newstring);
   set old;
   do i = 1 to countw(string, ';');
      word = scan(string, i, ';');
      if prxmatch('/#\d+/', word) = 0 then do;
         newstring = compress(word, '#');
         output;
      end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Sep 2022 19:55:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835493#M330310</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-27T19:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: Strip values from a varchar field and add carriage return?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835494#M330311</link>
      <description>&lt;P&gt;Which operating system is the target? The carriage return character is different in ASCII or EBCDIC text.&lt;/P&gt;
&lt;P&gt;How will the data be "pulled into the spreadsheet"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 19:58:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835494#M330311</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-27T19:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: Strip values from a varchar field and add carriage return?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835502#M330312</link>
      <description>&lt;P&gt;After a bit more research, I was able to get a nested TRANWRD function to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tranwrd(tranwrd(compress(olddata,'','d'),';#;#','0a'x),';#','') as newdata&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 20:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strip-values-from-a-varchar-field-and-add-carriage-return/m-p/835502#M330312</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2022-09-27T20:49:33Z</dc:date>
    </item>
  </channel>
</rss>

