SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

removing space

Reply
Occasional Contributor
Posts: 11

removing space

I am bringing the data from oracle. one of the character variable has value like

abc 25

spc 26

xy 20

I have used strip unction to remove the space. But when I compare the data with source value doesn't match. Also tried TRIMN(LEFT()). One more thing I don't want to delete the space between the values.

PROC Star
Posts: 1,167

Re: removing

You are using the strip function correctly. I wonder if you've got an encoding issue between Oracle and SAS.

To show you that the strip function is working, here's a code sample you can play with.

Tom

data have;
   length cvar $ 30;
   cvar = 'abc 25'; output;
   cvar = ' abc 25'; output;
   cvar = 'abc 25 '; output;
   cvar = ' abc 25 '; output;
run;

data want;
   set have;
   cvar2 = strip(cvar);
run;

proc tabulate data=want;
   class cvar2;

   table cvar2, n;
run;

Valued Guide
Posts: 860

Re: removing

Do you mean that you are pulling data into sas from oracle, then loading back to oracle and comparing your new file to the original?

If so I don't think that the new dataset is the problem, it looks like you are using the strip() function correctly.  It could be the original data or an issue during the transfer.

Valued Guide
Posts: 860

Re: removing space

This seems like a lot for your purpose but I'm sure it'll work.  If it's a large dataset I'd put in a where clause too.  Scan() will separate by the blank you want to keep and catx() will strip each variable but use the space as a deliminator.

Hope it helps:

data have;

infile cards dsd;

input char $;

cards;

abc 25

spc 26

xy 20

;

run;

data want;

set have;

cchar = scan(char,1,'');

nchar = scan(char,2,'');

if _N_ => 1 then do;

new_var = catx(' ',cchar,nchar);

end;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 338 views
  • 0 likes
  • 3 in conversation