DATA Step, Macro, Functions and more

Picking observations per firm with cetain variable is available

Reply
Contributor
Posts: 26

Picking observations per firm with cetain variable is available

 

The following dataset shows that the firm with gvkey 1011 has four observations that 'emps5' variable is available and the firm with gvkey 1012 has 0 observation that 'emps5' variable is available. Is there any sas program that picks only firm-observations per each firm that  at least three observations of 'emps5' variables are avaiable using 'sql' statement?

Thank you for your help

 

 

 

 

gvkey

001011

 

 

fyear

1988

.

 

emps5

0010111989.
0010111990.
00101119910.01495
00101119920.01378
00101119930.01339
00101119940.01415
0010121988.
0010121989.
Trusted Advisor
Posts: 1,228

Re: Picking observations per firm with cetain variable is available

What is the required output? If you want to list all variables for those gvkey having at least 3 values for emps5 then following code may provide you the desired output.

 

proc sql;

select * from have

group by gvkey

having count(emps5)>=3;

quit;

Super User
Posts: 19,791

Re: Picking observations per firm with cetain variable is available

Does it matter if the years are consecutive, or is any three years valid?

Contributor
Posts: 26

Re: Picking observations per firm with cetain variable is available

Thanks The following code works well.

proc sql; create table want  select * from have group by gvkey

having count(emps5)>=3; quit;

 

Is there any condition should be incldued in the code that the three years are consecutive?

Thanks again

Contributor
Posts: 26

Re: Picking observations per firm with cetain variable is available

Hi,

 

The following code enables me to capture observations with the number of variable 'emps5' is greater than 3.

proc sql; create table want  select * from have group by gvkey

having count(emps5)>=3; quit;

 

Is there any condition should be incldued in the code that the three years are consecutive?

Thank you for your help

Super User
Posts: 19,791

Re: Picking observations per firm with cetain variable is available

To clarify, the 3 years should be consecutive?

The method provided does not support finding 3 consecutive years and needs modification if that is the case. 

Contributor
Posts: 26

Re: Picking observations per firm with cetain variable is available

Hi Reeza,

Yes. the 3 years should be consecutive.

Thank you for your help

Contributor
Posts: 26

Re: Picking observations per firm with cetain variable is available

Hi Reeza,

 

Do you have a suggested code for picking up consecutive observations of three years?

Thank you very much

Ask a Question
Discussion stats
  • 7 replies
  • 235 views
  • 0 likes
  • 3 in conversation