BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
HI i want to add '0' before the id variable by using do until can any one help me.


data a;
input id $;
len=length(id);
do until (len=5);
a='0';
id=a||id;
end;
stop;
output;
cards;
1
01
001
run;

output
00001
00001
00001
2 REPLIES 2
GertNissen
Barite | Level 11
Must it be by using the do loop ?

Or perhaps you can use the following

data a;
input id 8.;
id2=put(id,z5.);
cards;
1
01
001
;
run;
ballardw
Super User
You need to update the len value within the DO loop.
Also, if you want to see the results of each iteration of the loop you need the OUTPUT within the loop as well.


data a;
input id $;
len=length(id);
a='0';
do until (len=5);
id=a||id;
len=length(id);
output;
end;
cards;
1
01
001
run;

You also should consider what might happen if the length of your input variable is greater than 5.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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