code to select specific firms from a sample

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

code to select specific firms from a sample


Hi All,

I want to pick up firms that meet my specific condition. For instance, my subset of sample looks as follows:

Firm     Year     Condition

A          2001    10-K

A          2002     10-K

A          2003     10-K

B          2001     10-K,8-K

B          2002     10-K,8-K

C          2001     10-Q,8-K

From this sample, I want to pick firms that has only 10-K as condition. (Condition is a character variable). Currently I am using the following code:

Data Want, set Have;

where Condition Contains '10-K';

run;

This code, however, select Firm A and Firm B. I want to select only firm A. I want the output to look as follows:

Firm     Year     Condition

A          2001    

A          2002

A          2003     10-K

Can someone please tell me how can I do it?


Accepted Solutions
Solution
‎03-11-2013 02:17 PM
Super User
Posts: 17,863

Re: code to select specific firms from a sample

Change your where condition to equals rather than contains.

View solution in original post


All Replies
Super Contributor
Posts: 578

Re: code to select specific firms from a sample

I'm not sure anyone will be able to help if we can't understand what is driving the results that you're looking for.  Can you describe how you selected the rows in your desired output?

Contributor
Posts: 28

Re: code to select specific firms from a sample

My desired output should contain only firms that have 10-K as condition. If the condition for any firm includes 10-K and anything else, I do not want to select those firms in my output. In other words, if my sample has three firms: A, B, C, I want to have only Firm A in my output.


Solution
‎03-11-2013 02:17 PM
Super User
Posts: 17,863

Re: code to select specific firms from a sample

Change your where condition to equals rather than contains.

Super User
Posts: 5,085

Re: code to select specific firms from a sample

Reeza's correct in that this will take you a long way:

where Condition = '10-K';

Other things to think about ...

Did you really want to blank out CONDITION for all but the last observation per FIRM?  If so, you'll need to add to the DATA step:

by firm;

if last.firm=0 then condition=' ';

Is it guaranteed that CONDITION will be constant for all of a firm's observations?  What would you want to happen here:

Firm   Year   Condition

D       2001   10-K

D       2002    8-K

D       2003   10-K

Good luck.

Contributor
Posts: 28

Re: code to select specific firms from a sample

Yes, the condition will be constant for all of a firm's observations. Thanks for the code.


☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 243 views
  • 6 likes
  • 4 in conversation