BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
4 REPLIES 4
Doc_Duke
Rhodochrosite | Level 12
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.
rickpaulos
Obsidian | Level 7

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.

 

 

 

 

 

LinusH
Tourmaline | Level 20
Trim is for trailing blanks. Try left().
Data never sleeps
rickpaulos
Obsidian | Level 7

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 2244 views
  • 0 likes
  • 4 in conversation