BookmarkSubscribeRSS Feed
hunluuu947
Calcite | Level 5
I want to create a dataset that have three variables(customer_num, total_bads, and current_bads). For every observation I want current_bads =customer_num and total_bads is then deducted by the number of current_bads until total_bads =0

For example(the initial total_bads is 60):
Customer_num Current_bads Total_bads
19 19 41
10 10 31
25 25 6
20 6 0
30 0 0
15 0 0

I am trying to use loop but my code doesn’t stop when total_bads reaches 0.

Can someone help me with it? Thank you such!
1 REPLY 1
Tom
Super User Tom
Super User

Show the code you tried.

Show the result you want.

Take the time to convert the data into code that create a dataset so those that want to help don't have to type in your numbers.

Notice it is not actually any more work than you already did to post the listing of the data.

data have;
  input Customer_num Current_bads Total_bads;
cards;
19 19 41
10 10 31
25 25  6
20  6  0
30  0  0
15  0  0
;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1 reply
  • 577 views
  • 0 likes
  • 2 in conversation