DATA Step, Macro, Functions and more

Perhaps a Hidden Character

Reply
N/A
Posts: 0

Perhaps a Hidden Character

I have two text string. One read from an excel file and the other from a sas data set. For some reason, they do not match according to SAS 9.1.3.

I tested the following code on windows. I did not type the string, I copied and pasted from the source files. I can't see any differences in the string. However, SAS did not evaluate them as equal.

Any ideas would be appreciated.

data test;
a='MINOCYCLINE HYDROCHLORIDE';
b='MINOCYCLINE HYDROCHLORIDE';
if trim(left(a))=trim(left(b)) then c=1;
else c=0;
output;
run;

Logs:
31 data test;
32 a='MINOCYCLINE HYDROCHLORIDE';
33 b='MINOCYCLINE HYDROCHLORIDE';
34 if trim(left(a))=trim(left(b)) then c=1;
35 else c=0;
36 output;
37 put a= b= c=;
38 run;

a=MINOCYCLINE HYDROCHLORIDE b=MINOCYCLINE HYDROCHLORIDE c=0
NOTE: The data set WORK.TEST has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.00 seconds


39
40 proc print; run;

NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Trusted Advisor
Posts: 2,113

Re: Perhaps a Hidden Character

An unprintable character is likely it. When I cut and paste your code into my SAS 9.2, I got c=1, so they matched.

You can examine the character strings more closely by using a hex format.
Contributor
Posts: 25

Re: Perhaps a Hidden Character

[ Edited ]

similar problem with data imported from Access.

 

FORMAT fname $HEX20.;

PROC PRINT;

  VAR fname;

RUN;

 

I get this: 20444F55474C41532020

20 is ascii for a space.

but TRIM(fname) does not remove the leading space.

ANYALPHA(fname) still returns 2.

 

 

 

 

 

Super User
Posts: 5,257

Re: Perhaps a Hidden Character

Trim is for trailing blanks. Try left().
Data never sleeps
Contributor
Posts: 25

Re: Perhaps a Hidden Character

Thanks.  The joys of regularly programming in 4 different langauges.

 

in MS:

Returns a string that contains a copy of a specified string

without leading spaces (LTrim),

without trailing spaces (RTrim), or

without leading or trailing spaces (Trim).

 

IN SAS

TRIM Function

Removes trailing blanks from a character string, and returns one blank if the string is missing.

 

BTRIM Function

Optional Arguments

btrim-specification

is one of the following:

LEADING

removes the blanks or specified characters from the beginning of the character string.

TRAILING

removes the blanks or specified characters from the end of the character string.

BOTH

removes the blanks or specified characters from both the beginning and the end of the character string.

Default BOTH
Ask a Question
Discussion stats
  • 4 replies
  • 170 views
  • 0 likes
  • 4 in conversation