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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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