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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1003 views
  • 3 likes
  • 4 in conversation