Prev: proc freq and proc means gives different percentage?
Next: A link to a collection of tutorials and videos on R.
From: Chandra on 9 Apr 2010 14:22 Hello All, I have a input data set containing Loan_Id 10 20 30 30 30 40 I want to create three datasets from the above dataset. Data1: removing all repeated loan numbers 10 20 40 Data2: First two occurences of duplicates 30 30 Data3: Last occurence of duplicate 30 Please help me out. Thanks in advance.
From: Reeza on 9 Apr 2010 15:35 On Apr 9, 11:22 am, Chandra <sekhar...(a)gmail.com> wrote: > Hello All, > > I have a input data set containing > Loan_Id > 10 > 20 > 30 > 30 > 30 > 40 > > I want to create three datasets from the above dataset. > > Data1: removing all repeated loan numbers > 10 > 20 > 40 > > Data2: First two occurences of duplicates > 30 > 30 > > Data3: Last occurence of duplicate > 30 > > Please help me out. > Thanks in advance. This is untested, but basically sort the data by loan id and the use first last options combines with multiple output statements. You can control the first/last with the sort proc if you have other fields that matter. HTH, Reeza proc sort data=loans; by loanid; data uniquedata firsttwo lastone; set loan; by loanid; retain recordcount 0; if first.loanid then do; output uniqueone; output firsttwo; recordcount=1; end; else recordcount=recordcount+1; if recordcount=2 then output firsttwo; if last.loanid then output lastone; run;
From: Barry Schwarz on 10 Apr 2010 00:43
Is the following close to what you want if first.load_id and last.loan_id then output data1; else if not last.loan_id then output data2; else output data3; On Fri, 9 Apr 2010 11:22:24 -0700 (PDT), Chandra <sekhar211(a)gmail.com> wrote: >Hello All, > >I have a input data set containing >Loan_Id >10 >20 >30 >30 >30 >40 > >I want to create three datasets from the above dataset. > >Data1: removing all repeated loan numbers >10 >20 >40 > >Data2: First two occurences of duplicates >30 >30 > >Data3: Last occurence of duplicate >30 > >Please help me out. >Thanks in advance. -- Remove del for email |