BookmarkSubscribeRSS Feed
kimx0961
Obsidian | Level 7

 

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.
7 REPLIES 7
stat_sas
Ammonite | Level 13

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;

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

kimx0961
Obsidian | Level 7

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

kimx0961
Obsidian | Level 7

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

Reeza
Super User

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. 

kimx0961
Obsidian | Level 7

Hi Reeza,

Yes. the 3 years should be consecutive.

Thank you for your help

kimx0961
Obsidian | Level 7

Hi Reeza,

 

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

Thank you very much

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!

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