HouseNo | PersonNo | Age |
---|---|---|
1 | 1 | 12 |
1 | 2 | 21 |
2 | 1 | 55 |
2 | 2 | 35 |
2 | 3 | 40 |
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
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
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;
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 No | Person No | Age | Item Code |
---|---|---|---|
1 | 1 | 12 | 01 |
1 | 1 | 12 | 02 |
1 | 2 | 21 | 03 |
1 | 2 | 21 | 04 |
2 | 1 | 15 | 01 |
2 | 2 | 45 | 05 |
2 | 3 | 50 | 06 |
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
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
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.
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.