<?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: prxparse in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26034#M5939</link>
    <description>PeterC,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the reply. It looks like to me their are a few different ways to do this. prxparse is not working as I expected though. I ended up using translate although I like how your method protects the commas that are not delims.&lt;BR /&gt;
&lt;BR /&gt;
This seemed to work:&lt;BR /&gt;
&lt;BR /&gt;
global serverOS infdlm;&lt;BR /&gt;
let origfile =&lt;BR /&gt;
%let newfile =&lt;BR /&gt;
%let serverOS = %substr(&amp;amp;sysscp,1,2);&lt;BR /&gt;
/* Macro to set tab delimeter */&lt;BR /&gt;
%macro setdlm;&lt;BR /&gt;
/* Windows */&lt;BR /&gt;
%if (&amp;amp;serverOS eq WI) %then %do;&lt;BR /&gt;
   %let infdlm='09'x;&lt;BR /&gt;
%end;&lt;BR /&gt;
/* Unix */&lt;BR /&gt;
%else %if (&amp;amp;serverOS eq HP) %then %do;&lt;BR /&gt;
   %let infdlm='09'x;&lt;BR /&gt;
%end;&lt;BR /&gt;
/* zOS */&lt;BR /&gt;
%else %if (&amp;amp;serverOS eq OS) %then %do;&lt;BR /&gt;
   %let infdlm='05'x;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
   %put ERROR: Invalid value specified for serverOS;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%mend setdlm;&lt;BR /&gt;
%setdlm;&lt;BR /&gt;
&lt;BR /&gt;
/* Datastep to turn comma delim file to tab delim */&lt;BR /&gt;
/* on a Windows Unix  MVS Operating System */&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 file "&amp;amp;newfile" LRECL = 5000;&lt;BR /&gt;
 infile "&amp;amp;origfile" LRECL = 5000 TRUNCOVER;&lt;BR /&gt;
 input;&lt;BR /&gt;
&lt;BR /&gt;
 _infile_ =translate(_infile_,&amp;amp;infdlm,',');&lt;BR /&gt;
 put _infile_;&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 05 May 2009 13:52:32 GMT</pubDate>
    <dc:creator>SASTalk</dc:creator>
    <dc:date>2009-05-05T13:52:32Z</dc:date>
    <item>
      <title>prxparse</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26030#M5935</link>
      <description>I'm using prxparse to take a raw datafile comma delim and chage it to a tab delim file. My issue I am having when I run the find replace code, it replaces the comma's with \t as literal instead of as tab. Please advise:&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;Code:&lt;/U&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;data _null_;&lt;BR /&gt;
 file "&amp;amp;newfile" LRECL = 2000;&lt;BR /&gt;
 infile "&amp;amp;origfile" LRECL = 900 TRUNCOVER;&lt;BR /&gt;
 input name $ 1-999;&lt;BR /&gt;
  name = prxparse('s/,/\t/');&lt;BR /&gt;
  call prxchange(name,-1,_infile_);&lt;BR /&gt;
  put _infile_;&lt;BR /&gt;
run;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Here is a snippet of what its doing:&lt;BR /&gt;
&lt;BR /&gt;
2.2.2\t0\t0\t2008\t5\t5\t4\t0\t1\t439\t0\t0\t0\t5.2\t

Message was edited by: SASTalk</description>
      <pubDate>Thu, 30 Apr 2009 21:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26030#M5935</guid>
      <dc:creator>SASTalk</dc:creator>
      <dc:date>2009-04-30T21:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: prxparse</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26031#M5936</link>
      <description>try replacing \t with '09'x&lt;BR /&gt;
&lt;BR /&gt;
Note:   On ASCII systems (PC, UNIX, MAC, VMS) the hex representation of a TAB character is '09'x. On EBCDIC systems (VM, MVS, VSE) the hex representation of a TAB is '05'x.</description>
      <pubDate>Fri, 01 May 2009 11:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26031#M5936</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-05-01T11:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: prxparse</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26032#M5937</link>
      <description>This is another solution&lt;BR /&gt;
* create test input data*;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  file 'c:\temp\comdlm.txt';&lt;BR /&gt;
  put "Samuel B. Thompson" ',' "04/28/1995" ',' "Raleigh";&lt;BR /&gt;
  put "Suzy B. Thomspon" ',' "5/1/1993" ',' "Wake Forest";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data info;&lt;BR /&gt;
  infile 'c:\temp\comdlm.txt' DSD dlm=',' truncover;&lt;BR /&gt;
  input name :$30. DOB :mmddyy8. city :$20.;&lt;BR /&gt;
  file 'c:\temp\tabdlm.txt' dlm='09'x;&lt;BR /&gt;
  put name :$30. DOB :mmddyy8. city :$20.;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 01 May 2009 11:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26032#M5937</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-05-01T11:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: prxparse</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26033#M5938</link>
      <description>When  replacing commas with tabs, consider, &lt;B&gt;protected&lt;I&gt; embedded &lt;/I&gt;commas&lt;/B&gt;. For Example:-&lt;BR /&gt;
First some sample data including an embedded comma, properly protected..[pre]DATA _null_ ;&lt;BR /&gt;
  input ;&lt;BR /&gt;
  file "your_file" ;&lt;BR /&gt;
  _infile_ = trim( _infile_ );&lt;BR /&gt;
  put _infile_  ;&lt;BR /&gt;
list;cards4 ;&lt;BR /&gt;
a,b,c,d,&lt;BR /&gt;
1,"AB,c",3,";",5&lt;BR /&gt;
,2,,4,&lt;BR /&gt;
email,"Goodnight, J;Thompson, Samuel B.",3,4,5&lt;BR /&gt;
1,,3,,5&lt;BR /&gt;
;;;;[/pre] Next, derive the number of column headers. Which I would hope is an adequate indicator for the file[pre]data _null_  ;  &lt;BR /&gt;
   infile "your_file" dsd dlm=','  lrecl=10000 col=c length=l ;&lt;BR /&gt;
   do col=1 by 1 until( c &amp;gt; l ) ;&lt;BR /&gt;
      input cname :$40. @@ ;&lt;BR /&gt;
   end ; &lt;BR /&gt;
   put "INFO: there are " col " columns" ;&lt;BR /&gt;
   call symputx( 'n_cols', col ) ;&lt;BR /&gt;
  stop ;&lt;BR /&gt;
run ;      [/pre] Finally ready to read, sensitive to commas embedded and protected among data values[pre]data _null_ ;&lt;BR /&gt;
   infile "your_file"  dsd dlm=','   lrecl=100000 truncover;&lt;BR /&gt;
     file "your_file2" dsd dlm='09'x lrecl=100000  ;&lt;BR /&gt;
   length col1-col&amp;amp;n_cols $32767 ;&lt;BR /&gt;
   input  (col:)(:) ;&lt;BR /&gt;
     put  (col:)(:) ;&lt;BR /&gt;
LIST;&lt;BR /&gt;
run ;[/pre]although that has completed the work required, the following step conveniently displays the '09'x as the new column delimiters, with protected commas remaining among the data[pre]data _null_ ;&lt;BR /&gt;
   infile "your_file2"   ;&lt;BR /&gt;
    INPUT @ ; &lt;BR /&gt;
LIST;&lt;BR /&gt;
run ;[/pre]&lt;BR /&gt;
Hope that is clear and helps.&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Mon, 04 May 2009 21:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26033#M5938</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-05-04T21:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: prxparse</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26034#M5939</link>
      <description>PeterC,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the reply. It looks like to me their are a few different ways to do this. prxparse is not working as I expected though. I ended up using translate although I like how your method protects the commas that are not delims.&lt;BR /&gt;
&lt;BR /&gt;
This seemed to work:&lt;BR /&gt;
&lt;BR /&gt;
global serverOS infdlm;&lt;BR /&gt;
let origfile =&lt;BR /&gt;
%let newfile =&lt;BR /&gt;
%let serverOS = %substr(&amp;amp;sysscp,1,2);&lt;BR /&gt;
/* Macro to set tab delimeter */&lt;BR /&gt;
%macro setdlm;&lt;BR /&gt;
/* Windows */&lt;BR /&gt;
%if (&amp;amp;serverOS eq WI) %then %do;&lt;BR /&gt;
   %let infdlm='09'x;&lt;BR /&gt;
%end;&lt;BR /&gt;
/* Unix */&lt;BR /&gt;
%else %if (&amp;amp;serverOS eq HP) %then %do;&lt;BR /&gt;
   %let infdlm='09'x;&lt;BR /&gt;
%end;&lt;BR /&gt;
/* zOS */&lt;BR /&gt;
%else %if (&amp;amp;serverOS eq OS) %then %do;&lt;BR /&gt;
   %let infdlm='05'x;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
   %put ERROR: Invalid value specified for serverOS;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%mend setdlm;&lt;BR /&gt;
%setdlm;&lt;BR /&gt;
&lt;BR /&gt;
/* Datastep to turn comma delim file to tab delim */&lt;BR /&gt;
/* on a Windows Unix  MVS Operating System */&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 file "&amp;amp;newfile" LRECL = 5000;&lt;BR /&gt;
 infile "&amp;amp;origfile" LRECL = 5000 TRUNCOVER;&lt;BR /&gt;
 input;&lt;BR /&gt;
&lt;BR /&gt;
 _infile_ =translate(_infile_,&amp;amp;infdlm,',');&lt;BR /&gt;
 put _infile_;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 05 May 2009 13:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/prxparse/m-p/26034#M5939</guid>
      <dc:creator>SASTalk</dc:creator>
      <dc:date>2009-05-05T13:52:32Z</dc:date>
    </item>
  </channel>
</rss>

