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

Hello

I have a data set with bridge name, Condition, inspection and year

The condition of the bridge can have different number (4,5,6,7,8) for the same bridge and the bridge name is repeated in my data set, not all the bridges are repeated though.

I want to filter bridge that has at least 2 different conditions (I don't want to specify the condition Number neither the bridge name.) How could I proceed?

 

 

for example bridge P505 below has 3 condition (that is the type I want to keep) and bridge P416 only have 1 condition (I don't want to keep that). I have about 900 rows

thanks

Blandine_0-1604611030188.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

It is not nice to discuss a requirement like "bridge" without explicitly tieing it to the variable name.

You don't indicate any need to consider the other variables

Something like this might work. You did not supply an example of what you actually expect the result to be.

"Filter" can have many meanings. This gets you a list of the "bridges" that could be used to select records with a join or data step merge.

 

proc sql;
   create table multipleconditions as
   select stucture_number_008, count(superstructure_cond_59) as condcount
   from (select distinct stucture_number_008, superstructure_cond_59
         from yourdatasetnamegoeshere)
   group by stucture_number_008
   having   count(superstructure_cond_59)>1
   ;
quit;

 

 

View solution in original post

5 REPLIES 5
Blandine
Obsidian | Level 7

sorry but I am not sure I understand what you mean by "use a code box"

ballardw
Super User

It is not nice to discuss a requirement like "bridge" without explicitly tieing it to the variable name.

You don't indicate any need to consider the other variables

Something like this might work. You did not supply an example of what you actually expect the result to be.

"Filter" can have many meanings. This gets you a list of the "bridges" that could be used to select records with a join or data step merge.

 

proc sql;
   create table multipleconditions as
   select stucture_number_008, count(superstructure_cond_59) as condcount
   from (select distinct stucture_number_008, superstructure_cond_59
         from yourdatasetnamegoeshere)
   group by stucture_number_008
   having   count(superstructure_cond_59)>1
   ;
quit;

 

 

Reeza
Super User
proc sql;
create table want as
select *
from have
group by bridge<replace with correct variable names>
having count(distinct condition)>=2;
quit;

Replace the variable with your variable names and you can use the HAVING clause to filter your data. 

 


@Blandine wrote:

Hello

I have a data set with bridge name, Condition, inspection and year

The condition of the bridge can have different number (4,5,6,7,8) for the same bridge and the bridge name is repeated in my data set, not all the bridges are repeated though.

I want to filter bridge that has at least 2 different conditions (I don't want to specify the condition Number neither the bridge name.) How could I proceed?

 

 

for example bridge P505 below has 3 condition (that is the type I want to keep) and bridge P416 only have 1 condition (I don't want to keep that). I have about 900 rows

thanks

Blandine_0-1604611030188.png

 


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 544 views
  • 0 likes
  • 4 in conversation