BookmarkSubscribeRSS Feed
ginagrodin
Calcite | Level 5

.

5 REPLIES 5
PaigeMiller
Diamond | Level 26

I don't see why you say it is ignoring your upper bound.

 

In the loop, if cost goes over 300, then the loop stops. So when the cost hits 302.50, it stops. Isn't that what you want?

--
Paige Miller
ginagrodin
Calcite | Level 5
 
PaigeMiller
Diamond | Level 26

Can you please show us the desired output?


Can you explain your algorithm to compute cost?

--
Paige Miller
ginagrodin
Calcite | Level 5
 
novinosrin
Tourmaline | Level 20
data work.pets1;
input name $ item $ cost;
cards;
basil carrots 100
basil hay 50
basil carpet 250
zelda bones 10
zelda kibble 50
;
run;


data want;
 do until(last.name);
  set pets1;
  by name;
  do _n_=1 to 3 while(cost<300);
   cost=cost*(1.1);
  end;
  total=sum(cost,total);
  output;
 end;
run;

proc print noobs;run;
name item cost total
basil carrots 133.10 133.10
basil hay 66.55 199.65
basil carpet 302.50 502.15
zelda bones 13.31 13.31
zelda kibble 66.55 79.86

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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