BookmarkSubscribeRSS Feed
Sarvendra
Fluorite | Level 6

I have a dataset with ACCNO  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 .as below logic not working

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

6 REPLIES 6
Reeza
Super User

A Proc SQL step works nicely (untested)

proc sql;

     create table want as

select * from

have where accno in (select accno from have group by accno having count(accno)>3);

quit;

Sarvendra
Fluorite | Level 6

Thanks a lot Reeza its working absolutely fine. Smiley Happy Smiley Happy

SASKiwi
PROC Star

Your code has syntax errors. You are missing semicolons on the first two lines:

data ssingh.FINADVNEWariable;

set ssingh.FINADV;

Otherwise your code should work as long as the dataset on the SET statement is sorted.

Astounding
PROC Star

Perhaps a smaller issue ...

Your original post asks for count greater than or equal to 3.

gt means "greater than"

ge means "greater than or equal"

Sarvendra
Fluorite | Level 6

Thanks it was just a syntax error of semicolumn Smiley Happy

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

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
  • 6 replies
  • 1262 views
  • 0 likes
  • 5 in conversation