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

Hello again!

I would like to ask you how to get from "have" to "wanna" base.

Have:

Company, Year,

A,2001

A,2002

A,2003

A,2004

B,2001

B,2002

B,2003

C,2001

C,2002

C,2003

C,2004

Wanna:

Company, Year,

A,2001

A,2002

A,2003

A,2004

C,2001

C,2002

C,2003

C,2004

I know the logic, but cannot really figure out the code...

I should assign e.g. item for every observation and delete each company which has item number <4

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
select * from have group by company having count(distinct year)=4; 

Xia Keshan

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, few ways to do it in SQL, heres one:

proc sql;

  create table want as

  select company,year

  from  (

          select  *

                  ,count(1) as tmp

          from    have

          group by company

        )

  where tmp=4;

quit;

slchen
Lapis Lazuli | Level 10

data have;
input Company $ Year;
cards;
A 2001
A 2002
A 2003
A 2004
B 2001
B 2002
B 2003
C 2001
C 2002
C 2003
C 2004
;
run;
proc sql;
select * from have group by company having count(*)=4;
quit;

Ksharp
Super User
select * from have group by company having count(distinct year)=4; 

Xia Keshan

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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