BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mirisage
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

3 REPLIES 3
Linlin
Lapis Lazuli | Level 10

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;

Tom
Super User Tom
Super User

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;

Mirisage
Obsidian | Level 7

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.

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
  • 3 replies
  • 1058 views
  • 3 likes
  • 3 in conversation