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.

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!

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.

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
  • 875 views
  • 0 likes
  • 3 in conversation