BookmarkSubscribeRSS Feed
sas_
Fluorite | Level 6

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;

13 REPLIES 13
Tom
Super User Tom
Super User

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;

sas_
Fluorite | Level 6

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

Tom
Super User Tom
Super User

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.

sas_
Fluorite | Level 6

i have checked by tranwrd it was not working

Patrick
Opal | Level 21

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.

Tom
Super User Tom
Super User

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.

Patrick
Opal | Level 21

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;

Tom
Super User Tom
Super User

Unforturnately the regex function does not consider A0 as a blank.

Ksharp
Super User

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

sas_
Fluorite | Level 6

HI sharp how can we write this prxcahnge any information to write that

Ksharp
Super User

What did you mean? I can't understand your words.

Ksharp

Patrick
Opal | Level 21

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.

Ksharp
Super User

Patrick.

Tom means 'A0'x   not '0A'x

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 1606 views
  • 6 likes
  • 4 in conversation