I have a dataset with ACCNOs as a variable.
we need to grab all the observations with ACCNOs with COUNT 3 or more .(or to create a new dataset with COUNT 3 or more)
I was thinking to implement this logic using first and last temporary variables but it was giving error.
When it will read the first observation of any individual account number then initialize n=0 and increment each iterating time and when it will read last observation of any individual account then if value of n greator than or equal to 3 the it should
Create a new dataset satisfying this condition.
Can there be any better logic for this .
data ssingh.FINADVNEWariable
set ssingh.FINADV
by ACCNO;
if first.ACCNO then n = 0;
n + 1;
if last.ACCNO and n gt 3 then output ;
run;
Please reply
Sarvendra
Do you want to grab all observations for an ACCNO that are => 3? Or just the last observation for each ACCNO if that one one is => 3.
Depending on your requirement, a group by and having in SQL seems simpler.
Hi Linush
I want to grab those observations of ACCNO for those individual accno for which count =>3.
Can you please give the logic in form of some dummy code.i have tried to implement
data ssingh.FINADVNEWariable
set ssingh.FINADV
by ACCNO;
if first.ACCNO then n = 0;
n + 1;
if last.ACCNO and n gt 3 then output ;
run;
but it was giving error.
Hoping for soon reply
Sarvendra
What error did you get? Note that you are missing semi-colons at the end of your DATA and SET statements.
Thanks Tom it was syntax error
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.