Separating subjects having multiple records - why my code not work?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

Separating subjects having multiple records - why my code not work?

Hi SAS Forum,

Of this data set, I wanted to separate only the subjects having multiple records.

data have;

informat Current_date date9.;

input Bank_number    Account_number  Current_date    Product $ 25-35 Balance     Arrears_Band $ 43-49;

Format Current_date date9.;

cards;

10 1000000000 31MAR2010    Personal OD 78.72 Current

10 1000000000 31MAY2010    Personal OD 62.84 Current

20 1000000000 31MAY2010    Personal OD 52.84 Current 

;

run;

Answer:

I should get the following data set.

Obs       Current_date     Bank_number    Account_number            Product Balance Arrears_Band

10 1000000000 31MAR2010    Personal OD 78.72 Current

10 1000000000 31MAY2010    Personal OD 62.84 Current

My effort

proc sort data=have  out= have_sorted;

   by bank_number account_number current_date;

run;

data want;

set have_sorted;

by bank_number account_number current_date;

if not first.account_number and last.account_number then output want;

run;

Problem:

I do not get the correct records.

Could any one help me.

Thanks

Mirisage


Accepted Solutions
Solution
‎09-24-2012 02:15 PM
Super Contributor
Posts: 1,636

Re: Separating subjects having multiple records - why my code not work?

try:

data have;

informat Current_date date9.;

input Bank_number    Account_number  Current_date    Product $ 25-35 Balance     Arrears_Band $ 43-49;

Format Current_date date9.;

cards;

10 1000000000 31MAR2010    Personal OD 78.72 Current

10 1000000000 31MAY2010    Personal OD 62.84 Current

20 1000000000 31MAY2010    Personal OD 52.84 Current 

;

run;

 

proc sort data=have  out= have_sorted;

   by bank_number account_number current_date;

run;

 

data want;

set have_sorted;

by bank_number account_number current_date;

if first.account_number and last.account_number then delete;

run;

proc print;run;

View solution in original post


All Replies
Solution
‎09-24-2012 02:15 PM
Super Contributor
Posts: 1,636

Re: Separating subjects having multiple records - why my code not work?

try:

data have;

informat Current_date date9.;

input Bank_number    Account_number  Current_date    Product $ 25-35 Balance     Arrears_Band $ 43-49;

Format Current_date date9.;

cards;

10 1000000000 31MAR2010    Personal OD 78.72 Current

10 1000000000 31MAY2010    Personal OD 62.84 Current

20 1000000000 31MAY2010    Personal OD 52.84 Current 

;

run;

 

proc sort data=have  out= have_sorted;

   by bank_number account_number current_date;

run;

 

data want;

set have_sorted;

by bank_number account_number current_date;

if first.account_number and last.account_number then delete;

run;

proc print;run;

Super User
Super User
Posts: 6,500

Re: Separating subjects having multiple records - why my code not work?

Because NOT take precedence over AND in the order of operations.  Add some () to group for you.

if  not (first.account_number and last.account_number) then output want;

Super Contributor
Posts: 338

Re: Separating subjects having multiple records - why my code not work?

Hi Linlin and Tom,

Many thanks to both of you.

Both of your suggestions work very well.

I usually post my queries in "SAS Procedures" among the following list of "Available Support Communities".

• SAS Procedures

• SAS Macro Facility, Data Step and SAS Language Elements

• SAS/GRAPH and ODS Graphics

• ODS and Base Reporting

• SAS Web Report Studio

• SAS Enterprise Guide

..................................

...................... and so on.

I cannot find this posting in "SAS Procedures" support community.

Could you please let me know which sub sommunity you will find my posting.

Thank you

Mirisage.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 342 views
  • 3 likes
  • 3 in conversation