Actually i am having data coming in text file the delimiter in ^ actually in some obs there is tab but it was removing the tab also now i want to replace tab with space
below example data has tab between ra and if i run it was remoivng the tab and i wnat to replace it with spaces
data l2;
input id$ 1-7 age ;
cards;
ra ok 56
run;
proc print;
run;
I am not clear what your question is. But if you have a text file and you want to have SAS expand the tabs into space when reading it look at the EXPANDTABS option on the INFILE statement.
data l2;
infile 'myfile.dat' expandtabs truncover ;
input id$ 1-7 age ;
run;
data l2;
infile cards expandtabs ;
input id$ 1-57 ;
id1=compbl(id);
cards;
user done ok
;
run;
Actually i want to replace tabs with space in the above from user to done there is tab and from done to k there is space i want to replace the tab with the space actually i have tryed it compbl,trim functions
output
user done ok
You can use TRANWRD to change tabs into spaces.
id1=compbl(tranwrd(id,'09'x,' '));
If you really have tabs inside your datalines inside your program file then you might want to change the settings on your editor so that all tabs are converted to spaces when you save. Personally I always do this as I find that tabs in source code cause more trouble than any benefit they might add.
i have checked by tranwrd it was not working
It should work. See below:
data _null_;
id='A'||'09'x||' A';
put id hex.;
id=compbl(tranwrd(id,'09'x,' '));
put id hex.;
run;
Unless you work on z/OS as there the Hex value for a tab would be 05.
It must not be a TAB then. Use either the list statement or the $HEX format to see what character it is. Perhaps it is 'A0'x which some editors use to store a non-breaking space.
Below code should replace any whitespace character with a "blank":
data _null_;
id='A'||'09'x||'0A'x||' A';
put id hex.;
id=compbl(prxchange('s/\s/ /o', -1, id));
put id hex.;
run;
Unforturnately the regex function does not consider A0 as a blank.
Tom. How about:
data _null_; id='A'||'09'x||'A0'x||' A'; put id hex.; id=compbl(prxchange('s/[\s\xA0]/ /o', -1, id)); put id hex.; run; data _null_; id='A'||'09'x||'A0'x||' A'; put id hex.; id=compbl(prxchange('s/\s|[[:^ascii:]]/ /o', -1, id)); put id hex.; run;
Ksharp
HI sharp how can we write this prxcahnge any information to write that
What did you mean? I can't understand your words.
Ksharp
Interesting - it worked with my Win7 SAS9.3 version.
1 data _null_;
2 id='A'||'09'x||'0A'x||' A';
3 put id hex.;
4 id=compbl(prxchange('s/\s/ /o', -1, id));
5 put id hex.;
6 run;
41090A2041
4120412020
But as Ksharp demonstrates it's only about little tweaks to the RegEx if it doesn't do what you need.
Patrick.
Tom means 'A0'x not '0A'x
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.