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-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
  • 4 replies
  • 617 views
  • 6 likes
  • 4 in conversation