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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 323 views
  • 0 likes
  • 2 in conversation