Help using Base SAS procedures

Proc compare results

Reply
Super Contributor
Posts: 272

Proc compare results

Dear,

 

I ran Proc compare on my data sets. I am attaching the documnet that I am explaning. 

 

For the EPOCH values, both in compare dataset and base dataset the values "SCREENING' are same. But the values are not matching and proc compare results  shows that compare values for EPOCH='SCREENING' are written on left side and bottom instead of right side.

 

My code;

 data one;
length EPOCH $40;
merge two (in=a) three;
by id;
if a;
if dtn ge sdate and dtn le edate then EPOCH='SCREENING';

run;

Super User
Posts: 18,498

Re: Proc compare results

One of your datasets, specified as compare, appears to have leading spaces. 

 

Try try strip or compress to remove the spaces. They may not be spaces but could be tabs or other white space characters so look at the compress options/modifiers if it doesn't work at first.  

Super Contributor
Posts: 272

Proc compare results

Dear,

 

I ran Proc compare on my data sets. I am attaching the documnet that I am explaning. 

 

For the EPOCH values, both in compare dataset and base dataset the values "SCREENING' are same. But the values are not matching and proc compare results  shows that compare values for EPOCH='SCREENING' are written on left side and bottom instead of right side.

 

My code;

 data one;
length EPOCH $40;
merge two (in=a) three;
by id;
if a;
if dtn ge sdate and dtn le edate then EPOCH='SCREENING';

run;

Super Contributor
Posts: 272

Re: Proc compare results

Dear,

 

I tried to find answer for this question. I could not. 

 

There are other IF statement for EPOCH. Why only EPOCH='SCREENING' is having the spaces and not matching. Does any body have any answer. I used compress and strip functions. It is still showing same results. Please help. Thanks.

Super User
Super User
Posts: 6,681

Re: Proc compare results

@Reeza already told you what is the most likely cause of the miss match.  One of the variables has leading spaces (or other non-graphic characters) and so they are NOT the same value.

 

if 'SCREENING' = '     SCREENING' then put 'FALSE';
else put 'TRUE';
Super Contributor
Posts: 272

Re: Proc compare results

I ran the following;

 

if 'SCREENING' = 'SCREENING' then put 'TRUE';
else put 'FALSE';

 

The log shows all TRUE. So there are no leading spaces. If any other possibility please help. Thanks. 

Super User
Posts: 18,498

Re: Proc compare results

Your test is not what you want, of course two strings are equal. 

 

Post the the code you used to trim/strip for the dataset that you claim did not work and the corresponding proc compare. 

Super Contributor
Posts: 272

Re: Proc compare results

My code;

 data one;
length EPOCH1 $40;
merge two (in=a) three;
by id;
if a;
if dtn ge sdate and dtn le edate then EPOCH1='SCREENING';

if EPOCH1 ^= '' then EPOCH=strip(EPOCH1);

run;

Super User
Posts: 18,498

Re: Proc compare results

Did you check to see if it still has some sort of leading spaces? As I mentioned in my first post, it may not be a space but some other white space character. 

 

Print the value with a hex format to see what it looks like.

 

put epoch hex16.;

 

 

 

 

 

Super User
Super User
Posts: 6,681

Re: Proc compare results

Take one of the observations where the values do not match and use a PUT statement with $HEX. format to see what values are actually in the strings. 

 

data _null_;
  set one firstobs=7 obs=7 ;
  put epoch $hex. ;
run;

data _null_;
  set two firstobs=7 obs=7;
  put epoch $hex.;
run;
Super Contributor
Posts: 272

Re: Proc compare results

Thanks for help.

 

I ran your code.

 

The Hex. format for 'SCREENING' in my data(compare)=53435245454E494E47

The Hex. format for 'SCREENING' in vendor data(base)=53435245454E494E47200A2020202020202020202020202020202020202020202020202020202020

 

What I have to before comparing the datasets. Please .Thanks

Super User
Posts: 18,498

Re: Proc compare results

It looks like your base data has trailing spaces. As far as I'm aware that should be ignored in your comparison. 

 

Run your proc compare code on these datasets gives you differences? Post the full code - including where you do the recode/trim and your output plese. 

 

Make sure to check the specific record numbers it's indicating. 

 

In a test case I can't replicate your issue.

 

data data1;
length epoch $20.;
epoch='Screening     ';
run;

data data2;
length epoch $9.;
epoch='Screening';
run;

proc compare base=data1 compare=data2;
run;
Super User
Super User
Posts: 6,681

Re: Proc compare results

The second one has a linefeed ('0A'x) character in the middle of it.

You can use COMPRESS() function to remove it.

 

X = COMPRESS(X,'0A'x);

 

Ask a Question
Discussion stats
  • 12 replies
  • 860 views
  • 3 likes
  • 3 in conversation