BookmarkSubscribeRSS Feed
Kiyai
Calcite | Level 5

HI guys,

 

I seek your help on how to code below. I've been searching on-line and most of the time found calculating difference between 2 rows not so much on tracking the values in 2 rows and use it as basis to calculate other variables.

 

In this example, i'm trying to calculate RSQN by tracking the value between 2 rows namely, outresv and cumpaid.

Whereas, OCC_NO is using claim & RSQN.

For the actual formula, I've attached the excel

 

How to create RSQN & OCC_NO.jpg

Thank you in advance for your expert assistance.

2 REPLIES 2
mkeintz
PROC Star

Why does sequence #10 have RSQN=4?  Shouldn't it be a 1 (with a corresponding increment to OCC_NO)?  After all the prior record (seq #9) has outresv cumpaid=0, which is putatively the signal to end one OCC_NO and start the next. 

 

And in sequence number 5 for the second claim, that is exactly what you do.  You reset RSQN=1 and increment OCC_NO from 1 to 2.

 

This program does that:

 

data have;
  input Claim $8.  SEQNO  OUTRESV :comma8.2  CUMPAID :comma8.2;
datalines;
A1696384	1	2,085.90	0.00
A1696384	2	2,642.30	0.00
A1696384	3	859.49	1,782.81
A1696384	4	0.00	1,782.81
A1696384	5	500.76	1,782.81
A1696384	6	0.00	2,283.57
A1696384	7	624.00	2,283.57
A1696384	8	62.44	2,845.53
A1696384	9	0.00	2,845.53
A1696384	10	0.00	2,845.53
A1821392	1	200	0
A1821392	2	0	200
A1821392	3	200	0
A1821392	4	0	0
A1821392	5	0	0
;
data want;
  set have;
  by claim;
  RSQN+1;

  if lag(outresv)=0 or first.claim=1 then do;
    RSQN=1;
    OCC_NO+1;
    if first.claim then OCC_NO=0;
  end;
run;

This program uses "summing statement" expressions, like the statement   "RSQN+1"  which says to 

  1. Increment RSQN by +1
  2. But don't reset RSQN to missing upon returning to the top of the DATA step.   

The longer if statement checks whether the record-in-hand is the start of a new OCC  (i.e. follows a OUTRESV=0) or start of a new claim number.  In both cases it increments OCC_NO, but in the case of a new claim, it immediately resets OCC_NO to 0.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Kiyai
Calcite | Level 5

Hi

 

 

ClaimSEQNOOUTRESVCUMPAIDGPAYRSQNOCC_NO
A169638412,085.900.000.00100
A169638422,642.300.000.00200
A16963843859.491,782.811,782.81300
A169638440.001,782.810.00400

 

 

 

ClaimSEQNOOUTRESVCUMPAIDGPAYRSQNOCC_NO
A16963845500.761,782.810.00101
A169638460.002,283.57500.76201

 

 

 

ClaimSEQNOOUTRESVCUMPAIDGPAYRSQNOCC_NO
A16963847624.002,283.570.00102
A1696384862.442,845.53561.96202
A169638490.002,845.530.00302
A1696384100.002,845.530.00402

 

 

 

 

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 545 views
  • 0 likes
  • 2 in conversation