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

I have an update statement for a table. Since LPAD does not work in SAS. is there a way to easily pad the zeros?

 

proc sql;
update <TABLE>
set UNIQUE_KEY = Compress('BI'||lpad('9161',7,'0')||'MTSMBE'||(put(CREATION_DATE_TIME,10.)));
quit;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Are you trying to generate a digit string from a number?  If so just use PUT() function and Z format.

put(9161,Z7.)

will generate the string '0009161'.

If your source is already a string (and cannot be converted to an integer using INPUT()) then you will need to work harder.

 

There are many answers to that question on this forum, although I suspect none of them are using the terminology of "LPAD()" whatever language you got that from.

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

If the table you are working with is not a "passthru" to an external database (such as Oracle or similar), then use format z10.

--
Paige Miller
Tom
Super User Tom
Super User

Are you trying to generate a digit string from a number?  If so just use PUT() function and Z format.

put(9161,Z7.)

will generate the string '0009161'.

If your source is already a string (and cannot be converted to an integer using INPUT()) then you will need to work harder.

 

There are many answers to that question on this forum, although I suspect none of them are using the terminology of "LPAD()" whatever language you got that from.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 2838 views
  • 0 likes
  • 3 in conversation