Google SAS Search

Add to Google

Wednesday, October 18, 2006

Hex It

Sometimes you need to specify an ASCII text character you can't see or print. You can specify any ASCII character using it's hex value and a hex literal in SAS. A hex literal in SAS is any of the 16 hex characters(0-9 and A-F) in quotes followed by an x. Such as '3A'x. You can see all the hex values for ASCII characters here:

A classic example of this is creating a tab delimited file using a data _null_ step.

data _null_;
set myData;
put @01 var1 '09'x
@10 var2 '09'x

Another useful time to specify hex characters is to get rid of them. Suppose you
have some "dirty data" that somehow has some weird non-printable characters in it. You look at the text using the hex32 format and discover that some form feed characters somehow snuck into there (0x0C). The easiest way to get rid of them is to compress() the variable. Such as
myVar = compress(myVar,'0C'x); 

This will remove all occurrences of the character specified from the text variable.