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
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;
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;
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;
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.
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.
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.