BookmarkSubscribeRSS Feed
Ishaan
Calcite | Level 5

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.

3 REPLIES 3
TomKari
Onyx | Level 15

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;

Steelers_In_DC
Barite | Level 11

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.

Steelers_In_DC
Barite | Level 11

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1049 views
  • 0 likes
  • 3 in conversation