BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shalmali
Calcite | Level 5

Hi All,

I have a dataset with the following information: Ticker, Year, and COUNT. I want to create a new subset of this data where I keep firms whose COUNT is not zero for any years in the sample. For instance my original dataset is as follows:

Ticker     Year     COUNT

A     2007     0

A     2008     0

A     2009     1

A     2010     1

A     2011     3

A     2012     0

B     2007     1

B     2008     3

B     2009     2

B     2010     1

B     2011     1

B     2012     1

From the above example, I want to create a new subset which will have information only for firm B because B did not have COUNT = 0 for any of the years.

Ticker     Year     COUNT

B     2007     1

B     2008     3

B     2009     2

B     2010     1

B     2011     1

B     2012     1

I would appreciate if someone would help me in getting this desired output.

Thank you for your time.

Shalmali

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input Ticker   $  Year     COUNT ;
cards;
A     2007     0
A     2008     0
A     2009     1
A     2010     1
A     2011     3
A     2012     0
B     2007     1
B     2008     3
B     2009     2
B     2010     1
B     2011     1
B     2012     1
;
run;
proc sql;
create table want as
 select * from have group by ticker having sum(count=0) eq 0;
quit;

Xia Keshan

View solution in original post

4 REPLIES 4
slchen
Lapis Lazuli | Level 10

proc sql;

select * from have group by ticker having min(count)^=0 order by year;          

quit;

stat_sas
Ammonite | Level 13

proc sql;

select distinct quote(trim(ticker)) into :firm separated by ',' from have where count=0;

select * from have where ticker not in (&firm);

quit;

Ksharp
Super User
data have;
input Ticker   $  Year     COUNT ;
cards;
A     2007     0
A     2008     0
A     2009     1
A     2010     1
A     2011     3
A     2012     0
B     2007     1
B     2008     3
B     2009     2
B     2010     1
B     2011     1
B     2012     1
;
run;
proc sql;
create table want as
 select * from have group by ticker having sum(count=0) eq 0;
quit;

Xia Keshan

shalmali
Calcite | Level 5

Thank you everyone for sharing the code.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1525 views
  • 6 likes
  • 4 in conversation