Search notes:

SAS format: hex

The format hex converts between strings/numbers an the hexadecimal representation of the memory that the string/number occupies.

Strings

data tq84_data;
 
   length txt $9;
   
/* A is 41 in hex, B 42 etc. */
   txt = cat('ABC', '010203'x, 'DEF');
   
   put txt= $hex.; /* txt=414243010203444546 */

run;
Github repository about-SAS, path: /programming/formats-informats/hex/from-string.sas
The following example uses the x modifier to create a string from a hexadecimal representation. With the hex format, it prints, of course, the same represanation from which it was created:
data _null_;
  chr              = '0102030405060708090a0b'x;
  put chr $hex50.; /* 0102030405060708090A0B */
run;
Github repository about-SAS, path: /programming/formats-informats/hex/from-x.sas

Numbers

data _null_;

  val =     0; put val hex4.; /* 0000 */
  val =     1; put val hex4.; /* 0001 */
  val =    16; put val hex4.; /* 0010 */
  val =   255; put val hex4.; /* 00FF */
  val =   256; put val hex4.; /* 0100 */
  val = 32767; put val hex4.; /* 7FFF */
  val = 32768; put val hex4.; /* 8000 */
  val = 65535; put val hex4.; /* FFFF */
  val = 65536; put val hex4.; /* 0000 */
  val = 65537; put val hex4.; /* 0001 */
  val =    -1; put val hex4.; /* FFFF */

run;
Github repository about-SAS, path: /programming/formats-informats/hex/from-number.sas

See also

informats and formats

Index