DATA Step, Macro, Functions and more

Reg:REplace tab with pipe or ^

Regular Contributor
Posts: 229

Reg:REplace tab with pipe or ^

data l i am having a record in a table  that data in that record is having with tab Ex: OBS_Data done this ok Now i want to split it in to obs Obs1  -Done Obs2- this obs3-ok or is there any way in the data that we can replace tab with | or ^ Ex:  done^this^ok

Trusted Advisor
Posts: 2,113

Re: Reg:REplace tab with pipe or ^

Your question isn't very clear to me.  If you have a string and want to replace the tab character with a | or ^, then you can just use the TRANSWRD function.

out = transwrd(in,'09'x,"|");

'09'x is the hex code for a tab in ASCII.  If it is an EBCDIC code, you'll need to look it up.

Doc Muhlbaier


Regular Contributor
Posts: 229

Re: Reg:REplace tab with pipe or ^

done this ok i have tryed on this data for example it shd be Input: done this ok output shd be done|this|ok you can che the text file

Valued Guide
Posts: 797

Re: Reg:REplace tab with pipe or ^

You probably want the double trailing @@, which allow you to easily read multiple observations from a single input data line.  I believe the tabs will just be treated as white space (so SAS will see each tab-deliminted value as a single variable), so you don't need any DLM stuff unless you have contiguous tabs:

data want;

  infile datalines

  input text : $10. @@;


done     this     ok


Super User
Super User
Posts: 6,502

Re: Reg:REplace tab with pipe or ^

TABS are not treated the sames as spaces unless you tell it differently on the INFILE statement.

You could use DLM='2009'x to treate space and tab as delimiters

Or use EXPANDTABS to have it convert the tabs to spaces on the way into the input buffer.

Ask a Question
Discussion stats
  • 4 replies
  • 4 in conversation