BookmarkSubscribeRSS Feed
SP2
Calcite | Level 5 SP2
Calcite | Level 5
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.
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Patrick
Opal | Level 21
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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