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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 711 views
  • 0 likes
  • 3 in conversation