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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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