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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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