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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1069 views
  • 0 likes
  • 3 in conversation