BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Smitha9
Fluorite | Level 6

Hi,

I have a data example:

ID

1

20

345

4654

I want to make the above ID to 5digits by filling the initial digits with Zero. 

Example:

ID

00001

00020

00345

04654

 

can anyone help me with this? thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Assuming these are numbers then the following will work:

 

age_displayed_format shows how to change the format for display. This does not change the underlying values so you can still do calculations if necessary. Sorts will be numeric still.

age_converted shows how to change the type into a character and you cannot do mathematical calculations on the variable any longer. Sorts will be alphabetic. 

I don't think in this case the sort issue matters.

 

data want;
set sashelp.class;

age_displayed_format = age;
format age_displayed_format z5.;

age_converted = put(age, z5.);
format age_converted $5.;

run;

proc print data=want;
var age:;
run;

@Smitha9 wrote:

Hi,

I have a data example:

ID

1

20

345

4654

I want to make the above ID to 5digits by filling the initial digits with Zero. 

Example:

ID

00001

00020

00345

04654

 

can anyone help me with this? thank you in advance


 

View solution in original post

1 REPLY 1
Reeza
Super User

Assuming these are numbers then the following will work:

 

age_displayed_format shows how to change the format for display. This does not change the underlying values so you can still do calculations if necessary. Sorts will be numeric still.

age_converted shows how to change the type into a character and you cannot do mathematical calculations on the variable any longer. Sorts will be alphabetic. 

I don't think in this case the sort issue matters.

 

data want;
set sashelp.class;

age_displayed_format = age;
format age_displayed_format z5.;

age_converted = put(age, z5.);
format age_converted $5.;

run;

proc print data=want;
var age:;
run;

@Smitha9 wrote:

Hi,

I have a data example:

ID

1

20

345

4654

I want to make the above ID to 5digits by filling the initial digits with Zero. 

Example:

ID

00001

00020

00345

04654

 

can anyone help me with this? thank you in advance


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 417 views
  • 0 likes
  • 2 in conversation