BookmarkSubscribeRSS Feed
Sarvendra
Fluorite | Level 6

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

4 REPLIES 4
LinusH
Tourmaline | Level 20

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.

Data never sleeps
Sarvendra
Fluorite | Level 6

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

Tom
Super User Tom
Super User

What error did you get?  Note that you are missing semi-colons at the end of your DATA and SET statements.

Sarvendra
Fluorite | Level 6

Thanks Tom it was syntax error Smiley Happy

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1226 views
  • 0 likes
  • 3 in conversation