BookmarkSubscribeRSS Feed
mnew
Calcite | Level 5
Experts:
Should we try to avoid using a variable list and the while / until condition together? It looks like the while / until does not kick in till the last variable value anyway.
Thanks.
data work.Test;
Amount=50;
do pay_time = 1,2,3,4 while (Amount LE 100);
Amount+ 50;
output;
end;
run;
proc print data=work.Test;
run;
data work.Test1;
Amount=50;
do pay_time = 1,2,3,4 until (Amount GE 100);
Amount+ 50;
output;
end;
run;
proc print data=work.Test1;
run;
4 REPLIES 4
data_null__
Jade | Level 19
I don't know what you should avoid. If you read the documentation carefully you will see that each comma separated specification can have it's own while/until clause.

[pre]
specification
denotes an expression or a series of expressions in this form

start
[/pre]

Very powerful!!
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The SAS log below, using a PUTLOG, not an OUTPUT, demonstrates clearly the SAS operational behavior with each:

1 data work.Test;
2 Amount=50;
3 do pay_time = 1,2,3,4 while (Amount LE 100);
4 Amount+ 50;
5 putlog _all_;
6 end;
7 run;

Amount=100 pay_time=1 _ERROR_=0 _N_=1
Amount=150 pay_time=2 _ERROR_=0 _N_=1
Amount=200 pay_time=3 _ERROR_=0 _N_=1
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds


8 /*
9 proc print data=work.Test;
10 run;
11 */
12 data work.Test1;
13 Amount=50;
14 do pay_time = 1,2,3,4 until (Amount GE 100);
15 Amount+ 50;
16 putlog _all_;
17 end;
18 run;

Amount=100 pay_time=1 _ERROR_=0 _N_=1
Amount=150 pay_time=2 _ERROR_=0 _N_=1
Amount=200 pay_time=3 _ERROR_=0 _N_=1
Amount=250 pay_time=4 _ERROR_=0 _N_=1
NOTE: The data set WORK.TEST1 has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Hello,

There is a difference between do i=1 to 4 while... and do i=1,2,3,4 while...



in the second one the expression is evaluated only for the last item (i=4).

in the first one the expression is evaluated at the beginning of each iteration.



Consider the differences between these examples:



[pre]
data work.Test;
Amount=50;
do pay_time = 1,2,3,4 while (Amount LE 100);
Amount+ 50;
output;
end;
run;
data work.Test1;
Amount=50;
do pay_time = 1 to 4 while (Amount LE 100);
Amount+ 50;
output;
end;
run;

proc print data=work.Test;
run;
proc print data=work.Test1;
run;
[/pre]

HTH,


Marius

mnew
Calcite | Level 5
Thanks to all three of you! I did not know we could combine While/Until with individual index variable values, multiple times ...in the do statement. Tested a few. I have to agree with Data _null_ that it is powerful. A nice surprise!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1575 views
  • 0 likes
  • 4 in conversation