Frits Verstraten
Frits Verstraten

Reputation: 2189

Transform numbers with 0 values at the beginning

I have the following dataset:

DATA survey; 
 INPUT zip_code number; 
 DATALINES; 
 1212 12
 1213 23
 1214 23
 ; 
 PROC PRINT; RUN;

I want to link this data to another table but the thing is that the numbers in the other table are stored in the following format: 0012, 0023, 0023.

So I am looking for a way to do the following:

Any thoughts on how I can get this working?

Upvotes: 0

Views: 59

Answers (3)

Tom
Tom

Reputation: 51621

Numbers are numbers so if the other table has the field as a number then you don't need to do anything. 13 = 0013 = 13.00 = ....

If the other table actually has a character variable then you need to convert one or the other.

char_number = put(number, Z4.);
number = input(char_number, 4.);

Upvotes: 2

NBut
NBut

Reputation: 1

If you need it to be four characters long, then you could do it like this:

want = put(input(number,best32.),z4.);

Upvotes: 0

Sean
Sean

Reputation: 1120

You can use z#. formats to accomplish this:

DATA survey; 
 INPUT zip_code number; 
 DATALINES; 
 1212 12
 1213 23
 1214 23
 9999 999
 8888 8
 ; 

data survey2;   
    set survey;
    number_long = put(number, z4.);
run;

Upvotes: 1

Related Questions