5

I am using the notalnum function in SAS. The input is a db field. Now, the function is returning a value that tells me there is a special character at the end of every string. It is not a space character, because I have used COMPRESS function on the input field.

How can I print the ACII value of the special character at the end of each string?

Victor
  • 16,609
  • 71
  • 229
  • 409

2 Answers2

3

The $HEX. format is the easiest way to see what they are:

data have;
  var="Something With A Special Char"||'0D'x;
run;

data _null_;
  set have;
  rul=repeat('1 2 3 4 5 6 7 8 9 0 ',3);  *so we can easily see what char is what;
  put rul=;
  put var= $HEX.;
run;

You can also use the c option on compress (var=compress(var,,'c');) to compress out control characters (which are often the ones you're going to run into in these situations).

Finally - 'A0'x is a good one to add to the list, the non-breaking space, if your data comes from the web.

Joe
  • 62,789
  • 6
  • 49
  • 67
1

If you want to see the position of the character within the ascii table you can use the rank() function, e.g.:

data _null_;
  string = 'abc123';
  do i = 1 to length(string);
    asc = rank(substr(string,i,1));
    put i= asc=;
  end;
run;

Gives:

i=1 asc=97
i=2 asc=98
i=3 asc=99
i=4 asc=49
i=5 asc=50
i=6 asc=51

Joe's solution is very elegant, but seeing as my hex->decimal conversion skills are pretty poor I tend to do it this way.

Robert Penridge
  • 8,424
  • 2
  • 34
  • 55