Your SAS programs, embedded in web apps and elsewhere

How to use SSN format

Accepted Solution Solved
Reply
N/A
Posts: 0
Accepted Solution

How to use SSN format

In a stored process I'm making, I have a character field coming in that contains Social Security numbers. Can I use the format=SSN11. format line against it, or does my character field have to be converted to numeric first?

Second question: In Proc Sql, can I use an input command (XYZ=INPUT(ABC,$11) to convert the character field to numeric, or does that have to be done in a data step?

Is there an "easy" way to do what I'm trying to accomplish?

Thanks in advance so much!

Accepted Solutions
Solution
‎09-01-2016 03:25 PM
SAS Super FREQ
Posts: 8,862

Re: How to use SSN format

[ Edited ]
Posted in reply to deleted_user

Hi:
Look in the documentation for the topics:
Functions and CALL Routines
INPUT Function

The bottom line is that to convert a CHARACTER variable to a number, you use the INPUT function like this:

 

newnumvar = INPUT(oldcharvar,numeric-informat.); (DATA step)
OR
INPUT(oldcharvar,numeric-informat.) as newnumvar (SQL)

So you were ALMOST right in your INPUT statement. Think of it this way, in order to turn your old character variable into a NEW numeric variable, you have to give the NUMERIC INformat to use.

See the example below.
cynthia

** make some data;
** ssnc is a 9 position character variable with SSN;
** ssn is a numeric variable;
data testit;
name = 'alan';
ssn = 123456789;
ssnc = '123456789';
output;

name = 'bob';
ssn = 002334444;
ssnc = '002334444';
output;
run;

ods listing;

proc sql ;
select name, ssn format=ssn11., ssnc,
input(ssnc,9.) as newssn format=ssn11.
from work.testit;
quit;


and the output:

name ssn ssnc newssn
-----------------------------------------
alan 123-45-6789 123456789 123-45-6789
bob 002-33-4444 002334444 002-33-4444

View solution in original post


All Replies
Solution
‎09-01-2016 03:25 PM
SAS Super FREQ
Posts: 8,862

Re: How to use SSN format

[ Edited ]
Posted in reply to deleted_user

Hi:
Look in the documentation for the topics:
Functions and CALL Routines
INPUT Function

The bottom line is that to convert a CHARACTER variable to a number, you use the INPUT function like this:

 

newnumvar = INPUT(oldcharvar,numeric-informat.); (DATA step)
OR
INPUT(oldcharvar,numeric-informat.) as newnumvar (SQL)

So you were ALMOST right in your INPUT statement. Think of it this way, in order to turn your old character variable into a NEW numeric variable, you have to give the NUMERIC INformat to use.

See the example below.
cynthia

** make some data;
** ssnc is a 9 position character variable with SSN;
** ssn is a numeric variable;
data testit;
name = 'alan';
ssn = 123456789;
ssnc = '123456789';
output;

name = 'bob';
ssn = 002334444;
ssnc = '002334444';
output;
run;

ods listing;

proc sql ;
select name, ssn format=ssn11., ssnc,
input(ssnc,9.) as newssn format=ssn11.
from work.testit;
quit;


and the output:

name ssn ssnc newssn
-----------------------------------------
alan 123-45-6789 123456789 123-45-6789
bob 002-33-4444 002334444 002-33-4444
N/A
Posts: 0

Re: How to use SSN format

Posted in reply to Cynthia_sas
So close, yet so far! Thanks for the information..... that'll come in handy for many Proc Sql's to come.
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 2998 views
  • 0 likes
  • 2 in conversation