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

I have a character variable that is an ID number with leading zeroes than force it to be 10 digits--e.g., 0000012345. I would like to remove one leading zero to make it have a width of 9. The below line accomplished what I had intended, but a code reviewer said that I should not use 1* to convert from character to numeric and suggested that I use an input statement.

ID=put(1*ID, z9.);

I have tried a few things (see below, for example), but can't get this to work.

ID=input(ID, $10.);
format ID z9.;

Any ideas?

I fear the solution is something very obvious, but I am new to SAS and am very much struggling with this.

1 ACCEPTED SOLUTION

Accepted Solutions
3 REPLIES 3
novinosrin
Tourmaline | Level 20
 want_id=put(input(id,10.),z9.);
ballardw
Super User

"Can't get this to work" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the <> to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

Ksharp
Super User
data have;
id='0000012345';
want_id=prxchange('s/^0//',1,strip(id));
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2245 views
  • 3 likes
  • 4 in conversation