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-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!

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.

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
  • 4 replies
  • 827 views
  • 0 likes
  • 3 in conversation