You’ll utility a DO WHILE remark in SAS to do some loop over and over again pace some status remainder true.
Please see examples display two other ways to utility this remark in apply.
Instance 1: DO WHILE Observation in SAS
Please see code presentations the way to utility a DO WHILE remark in SAS to manufacture a dataset that accommodates two variables referred to as var1 and var2 that proceed to generate pristine values pace the worth of var1 is not up to 100:
/*manufacture dataset the usage of DO WHILE remark*/
information my_data;
var1 = 1;
var2 = 1;
do pace(var1 < 100);
var1 = var1 + var2;
var2 = var1 * var2;
var1 + 1;
output;
finish;
run;
/*view dataset*/
proc print information=my_data;
The DO WHILE remark endured to generate pristine values for var1 and var2 pace the worth of var1 used to be not up to 100.
As soon as the worth of var1 exceeded 100, the DO WHILE remark blocked and pristine values blocked being added to the dataset.
Instance 2: DO WHILE Observation with TO Observation in SAS
Please see code presentations the way to utility a DO WHILE remark with a TO remark in SAS to manufacture a dataset that accommodates two variables referred to as var1 and var2 that proceed to generate pristine values pace the worth of var1 is not up to 10:
/*manufacture dataset the usage of DO WHILE remark with TO remark*/
information my_data;
var1 = 0;
do var2 = 1 to 5 pace(var1 < 10);
var1 = var2**3;
output;
finish;
run;
/*view dataset*/
proc print information=my_data;
The TO remark instructed SAS to struggle to generate values for var2 starting from 1 to five however most effective pace the worth of var1 used to be not up to 10.
As soon as the worth of var1 exceeded 10, the DO WHILE remark blocked and pristine values blocked getting added to the dataset.
Extra Assets
Please see tutorials give an explanation for the way to carry out alternative ordinary duties in SAS:
The best way to Significance IF-THEN-DO in SAS
The best way to Significance IF-THEN-ELSE in SAS
The best way to Take away Duplicates in SAS