BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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;

12 REPLIES 12
knveraraju91
Barite | Level 11

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;

knveraraju91
Barite | Level 11

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.

Tom
Super User Tom
Super User

@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';
knveraraju91
Barite | Level 11

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. 

Reeza
Super User

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. 

knveraraju91
Barite | Level 11

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;

Reeza
Super User

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.;

 

 

 

 

 

Tom
Super User Tom
Super User

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;
knveraraju91
Barite | Level 11

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

Reeza
Super User

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;
Tom
Super User Tom
Super User

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);

 

Reeza
Super User

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.  

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 3350 views
  • 3 likes
  • 3 in conversation