Help using Base SAS procedures

how do i retain observations with more than 4 reportdates

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

how do i retain observations with more than 4 reportdates

hi, thank you in advance for your kind attention.

i have 2 variables: COMPANYID and YEAR

COMPANYID is between 1-100. YEAR can be anywhere between 1950-2013

I want to keep the COMPANYIDs that have more than 10 years within them.

for example:

companyID 1 may have year 1950, 1951 only. i want to drop companyID 1 completely because i only see 2 years and my threshold is 10.

Can you provide me your guidance?

thank you!


Accepted Solutions
Solution
‎04-17-2014 10:40 PM
Super User
Posts: 19,855

Re: how do i retain observations with more than 4 reportdates

Do the years need to be consecutive, or do any 10 years count?

proc sql;

create table want as

select companyid, year, count(*) as count_years

from have

group by companyid

having count(year)>10;

quit;

View solution in original post


All Replies
Solution
‎04-17-2014 10:40 PM
Super User
Posts: 19,855

Re: how do i retain observations with more than 4 reportdates

Do the years need to be consecutive, or do any 10 years count?

proc sql;

create table want as

select companyid, year, count(*) as count_years

from have

group by companyid

having count(year)>10;

quit;

Frequent Contributor
Posts: 102

Re: how do i retain observations with more than 4 reportdates

thank you for your reply reeza.

what if i want them to fall in a specific time period? ie: 1950-1960? thank you much!

Super User
Posts: 19,855

Re: how do i retain observations with more than 4 reportdates

Add in a where clause, 1950 to 1960 is an 11 year period though.

proc sql;

create table want as

select companyid, year, count(*) as count_years

from have

where year between 1950 and 1960

group by companyid

having count(year)>10;

quit;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 179 views
  • 3 likes
  • 2 in conversation