BookmarkSubscribeRSS Feed
RobertHuey
Calcite | Level 5

Hi all,

I'm using the compare function in a data step to compare the values in two columns.  The length of the character string is 30 characters and the compare function says there is a difference in the 31st character.  I've trimmed the two variables and don't know why there is a difference.  The two cells say the same thing.  I've copied them over to excel and set them equal to one another and they check out.  All the other observations are matching as well.  Any help will be appreciated!

5 REPLIES 5
RobertHuey
Calcite | Level 5

Thanks, Hima but I was using the compare function and not the PROC.  See below.

 

result= compare(NamesFromFile, MasterNames)


Haikuo
Onyx | Level 15

You may have some invisible-unprinted character in your variables, such as 'tab'. The best way to tell the difference is to see what machine sees: the hex value, you can try to fiddle with some options, but that would depend on your luck.

data test;

     input (v1 v2) ($char4.);

     put v1=hex16. / v2=hex16.;

     rc1=compare(v1,v2); /*v1 is tailed by a 'blank' while v2 has a 'tab'*/

     rc2=compare(trim(v1),trim(v2));/*trim will only take off the blank, so it wouldn't work*/

     rc3=compare(trim(v1),trim(v2),':');/*with the modifier, it only compares the shortest char, which is 3, so now it works*/

     cards;

aaa aaa   

;

Regards,

Haikuo

RobertHuey
Calcite | Level 5


You're right.  The modifier worked! Thanks!

Haikuo
Onyx | Level 15

if you only want to compare the PRINTABLE part of your variable, use compress();

results=compare(compress(v1,,'kw'),compress(v2,,'kw'));

Haikuo

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
  • 5 replies
  • 2420 views
  • 2 likes
  • 3 in conversation