BookmarkSubscribeRSS Feed
apple
Calcite | Level 5
HouseNo
PersonNoAge
1112
1221
2155
2235
2340

I have a dataset like the above. I would like to identify all the HouseNo which have PersonNo who are over Age 50. How do I do so?

Thanks

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

Please try

data have;

    input houseno personno age;

    if age > 50;

cards;

1    1    12

1    2    21

2    1    55

2    2    35

2    3    40

;

proc print;

run;

Thanks,

Jagadish

Thanks,
Jag
art297
Opal | Level 21

Jagadish's code will select the correct HouseNos, but will select them multiple times if there are more than one PersonNo who is older than 50.  I'd suggest the following approach:

proc sql;

  select distinct HouseNo

    from have

      where Age gt 50

  ;

quit;

apple
Calcite | Level 5

proc sql;

  select distinct HouseNo

    from have

      where Age gt 50

  ;

quit;

Hi

This code works. But if I have a even more complicated dataset like the below:

House NoPerson NoAgeItem Code
111201
111202
122103
122104
211501
224505
235006

And I want the distinct House No and the Person No who meets the Age criteria and his Age, how do I modify the code?

Remember for each distinct House No & Person No, he can have multiple records due to the different Item Code.

Thank you

apple
Calcite | Level 5

Hi All

Another question is that if I want to find all HouseNo that DO NOT have any member with Age>50, how do I do so?

Thank you

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
  • 411 views
  • 0 likes
  • 3 in conversation