BookmarkSubscribeRSS Feed
redfishJAX
Calcite | Level 5
Please help...I am trying to run a loop and output all records within the by group until the runbal is less than or equal to 0. Obs in bold is what I want to output.

Here is the abbreviated dataset:
custid$ oblgid$ runbal
1234 A 1536
1234 A 0

1234 A 1536 (do not want this one to output)
1235 A 0
1236 A 500
1236 A 0

1236 A -500 (do not want this one to output)

Here is what I have so far, but can't seem to think of a way to get the right output. If I do a DO UNTIL 0 then it only outputs one row.

DATA MAXOBS_GT2_PAYDOWN;

SET MAXOBS_GT2;
BY CUSTID OBLGID;
RETAIN RUNBAL;
IF FIRST.OBLGID THEN DO;
RUNBALTEMP=CURRBALAMT;
RUNBAL=RUNBALTEMP;
END;
RUNBALTEMP=RUNBAL;
RUNBAL=RUNBALTEMP-PAID;

RUN;

Any help would be greatly appreciated.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
In the DATA step, use an OUTPUT statement, making it's execution conditional on your required IF/THEN condition, such as:

IF A LT TOT_A THEN OUTPUT;
redfishJAX
Calcite | Level 5
Thanks...

But I am not sure it will work since I don't always want to output if the condition is true. I want to output the obs until the value gets to zero (also output the zero value as well). The following obs after the value is zero, I want to exclude.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest you try some IF / THEN coding in your DATA step - add self-checking diagnostic statement such as:

PUTLOG '>DIAG> I am here.' / _ALL_;

With this additional log output, you will see each SAS variable value as your DATA step iterates -- you may need to put in multiple PUTLOG statements to experiment with your program.

I suspect that you can address your "conditional output" scenario with some statement in the form:

IF () THEN OUTPUT;


and you may need to keep a running SAS temporary numeric variable, either using possibly some combination of accumulation with a RETAIN and then DROP the temp variable.

Scott Barry
SBBWorks, Inc.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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