sas >> One liner to convert numeric ssn to 9-digit character

by anindya.lugbang » Mon, 28 Jul 2008 21:04:25 GMT

What about ssn2 = compress(put(ssn,z9.)) ?

On Mon, Jul 28, 2008 at 6:20 PM, JohnH < XXXX@XXXXX.COM > wrote:
> I need to create a flat file which contains a 9 digit social security
> number with the leading zeros. My SAS dataset contains an ssn as a
> numeric variable. The SAS ssn format contains the dashes so that does
> not work in a put or input statement. Does anyone know of a put
> statement with a format that would work in the data _null_ step that
> creates the flat file? Or, does someone know of some other one-liner
> that would create the 9-digit ssn with leading zeros as another
> variable that could then be put to the flat file? Thanks.
>

sas >> One liner to convert numeric ssn to 9-digit character

by hs AT dc-sug DOT org » Mon, 28 Jul 2008 21:05:02 GMT



Use the Z9. format.

sas >> One liner to convert numeric ssn to 9-digit character

by gerhard.hellriegel » Mon, 28 Jul 2008 21:11:44 GMT


what do you have against the SSN11. format?

data _null_;
x=1234567;
s=put(x,ssn11.);
put s=;
run;

Gerhard

sas >> One liner to convert numeric ssn to 9-digit character

by datanull » Mon, 28 Jul 2008 21:43:20 GMT

You don't need a new variable just print it with Z format.

188 data _null_;
189 input ssn :comma.;
190 put 'NOTE: SSN with Z9 format. ' ssn z9.;
191 format ssn ssn.;
192 list;
193 cards;

NOTE: SSN with Z9 format. 000990123
RULE: ----+----1----+----2----+----3----+
194 000-99-0123
NOTE: SSN with Z9 format. 012870033
195 012-87-0033

sas >> One liner to convert numeric ssn to 9-digit character

by dirk.vk » Mon, 28 Jul 2008 22:00:26 GMT

My response is a bit redundant... 5th in a row... Saying exactly the same as
the one preceding it... :-(

On the other group (i.e.:
http://groups.google.com/group/comp.soft-sys.sas/topics?lnk ) there was only
the question, none of the answers.

Similar Threads

1. One liner to convert numeric ssn to 9-digit character variable with leading zeros

I need to create a flat file which contains a 9 digit social security
number with the leading zeros.  My SAS dataset contains an ssn as a
numeric variable.  The SAS ssn format contains the dashes so that does
not work in a put or input statement.  Does anyone know of a put
statement with a format that would work in the data _null_ step that
creates the flat file?  Or, does someone know of some other one-liner
that would create the 9-digit ssn with leading zeros as another
variable that could then be put to the flat file?  Thanks.

2. Convert to numeric where Date field Numeric and Character

3. Change zipcode from numeric to 5 digit character

Hi All,

I have the zipcode variable with numeric values, I want to change it to
character variable with 5 digits, i.e add leading 0 to the zipcodes
that have only 4 digits.

eg.

zipcode
1234
4457
5687
32154

to 

zipcode
01234
04457
05687
32154

thanks,
richie

4. Numeric value (18 digit) to character value

5. Fetch Hexadecimal digits from Character and Convert them to Number

Hello,

I have a dataset where a column(say First_Cell) has values like -
40497000A041D
40497001E14E9
40497003C2399 etc..

These values are stored as CHARACTER type. The last 4 characters of
the above string identify HEXADECIMAL number.
I need to convert these last 4 characters to number. 

I think the path I need to follow is  -
1)Fetch last 4 characters from the string
2) Convert them to HEXADECIMAL value
3)Convert the HEXADECIMAL to Number type.

Is this approach right? If yes then should I use $HEXw. FORMAT &
INFORMATS? How do I go about achieving this?

Is there any other simpler and/or faster approach?

Pls. help.

Thanks
M.K.

6. a good practice to convert character to numeric

7. Convert from Character to Numeric

Trying to Convert from Character to Numeric. Can anyone please let me know
 what may be possible wrong with the following coding:

    format birthdtn DATE9.;
    birthdtn=input(compress(birthdt, '-'), date9.);


Getting following error:
NOTE: Invalid argument to function INPUT at line 2308 column 14.
SUBJID=0020033 SEX=Female BIRTHDT=19610424 birthdtn=. _ERROR_=1 _N_=1
NOTE: Invalid argument to function INPUT at line 2308 column 14.
SUBJID=0020033 SEX=Female BIRTHDT=19610424 birthdtn=. _ERROR_=1 _N_=2
NOTE: Invalid argument to function INPUT at line 2308 column 14.

Thank you.

8. A NEED FOR CONVERTING FROM CHARACTER TO NUMERIC