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
;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 537 views
  • 0 likes
  • 2 in conversation