The SAS Output Delivery System and reporting techniques

What is wrong with my data step?

Reply
Occasional Contributor SP2
Occasional Contributor
Posts: 8

What is wrong with my data step?

This is some basic question.
My code...
data Uniquepolicy;
set Sortedpolicy;
By POLICY_SK;
MAX_TRAN_SEQ_NUM= last.TRAN_SEQ_NUM;
run;
Sortedpolicy has variables POLICY_SK and TRAN_SEQ_NUM.It was sorted by POLICY_SK and then by TRAN_SEQ_NUM.I wanted all Policy_SK with largest TRAN_SEQ_NUM. I am getting same number of obs. in the new table Uniquepolicy. Please help.
Super Contributor
Super Contributor
Posts: 3,174

Re: What is wrong with my data step?

You will likely see in your SAS log a message about VARIABLE last.TRAN_SEQ_NUM IS UNINITIALIZED. Your BY statement does not specify this variable and so it is not being initialized by SAS as you might be expecting.

Suggested reading:

SAS Language Reference: Concepts, Definitions for BY-Group Processing:
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001330158.htm


Scott Barry
SBBWorks, Inc.
Respected Advisor
Posts: 3,887

Re: What is wrong with my data step?

Try this - and also do the suggested reading:

data Uniquepolicy;
set Sortedpolicy;
By POLICY_SK;
rename TRAN_SEQ_NUM=MAX_TRAN_SEQ_NUM;
/* output last row per distinct POLICY_SK */
if last.POLICY_SK then output;
run; Message was edited by: Patrick
Ask a Question
Discussion stats
  • 2 replies
  • 120 views
  • 0 likes
  • 3 in conversation