Numeric-to-Character Conversion, Using the PUT Function - SAS Programming

This rather interesting example came from a real problem that passed the desk of one of the authors.You have two SAS data sets that contain Social Security numbers. Data set ONE has them stored in a variable called ID as 9-digit numerics. Data set TWO has them stored in the variable ID as 11-byte character values (in the form 123-45-6789).You want to merge the two files. You have a choice: convert the numeric ID variable in ONE to character or the character ID variable in TWO to numeric. We show the former method:



The built-in SAS format SSN11.writes numerics as 11-byte character strings in the standard Social Security number format with dashes and leading zeros. By using the PUT function, you assign this character string to the variable ID.It is necessary to rename ID to SS temporarily since you want the 11-byte character variable to be called ID.

The RENAME option on the SET statement allows you to rename variables being read from the incoming data set. You can rename a number of variables using the syntax:

SETdatoset (RENAME=(oldvar1=newvar1 oldvar2=newvar2 ...));

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

SAS Programming Topics