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.
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;
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.
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.