BookmarkSubscribeRSS Feed
cindyforest7
Calcite | Level 5


Hello all,

I have a list of numbers under variable A:

A

1

3

45

5

4567

234

33

Now I want to get

A

00000001

00000003

00000045

00000005

00004567

00000234

00000033

Each number now will have 8 digits.

How to do it in SAS?

Thanks so much!

Cindy

3 REPLIES 3
ballardw
Super User

Is A numeric or character?

If numeric do you actually need a new variable or for it just to appear with leading zeroes? In this case you can just assign a format to display with zeroes: Format a z8. ;

If A is character there's a number of ways but

A = put(input(a, best8.),z8.) ; might work.

cindyforest7
Calcite | Level 5

Thanks!'

It is numeric, and I don't want to create a new variable.

If I want to merge two tables based on A (one table displays with zero, one table does not ), will changing formating work?

CTorres
Quartz | Level 8

If A is numeric in both SAS tables you should be able to merge the tables without changing anything.
The internal representation of A (numeric variable) is the same in both tables. The diference in the display should be because of the format in the table: Z8. (with leading zeroes) v.s. 8. or best8. or none (without leading zeroes)

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1084 views
  • 0 likes
  • 3 in conversation