BookmarkSubscribeRSS Feed
Mirisage
Obsidian | Level 7
Hi Colleagues,


I have a 10,703 observation size dataset like this.

data HH;
input pumfid PEFAMTYP_M deprived MD_Q02 MD_Q06 MD_Q14 WTFM;
cards;

1 1 2 1 2 2 1
2 7 1 2 1 6 1
3 7 2 6 6 1 1
4 7 2 7 1 7 1
5 1 2 1 7 9 1
6 1 2 1 9 9 1
7 7 1 1 1 7 1
8 1 2 6 1 2 1
9 7 2 7 1 1 1


;
run;

I need to find the count of families with all the following conditions.
1. who are deprived (i.e. deprived =1)
2. only family type 7 (i.e. PEFAMTYP_M = 7)
3. any one of MD_Q02 or MD_Q06 or MD_Q14 should have the code 1

I gave the following command but produce some strange frequency table.

proc surveyfreq data=HH;
tables pumfid;
WEIGHT WTFM;
where deprived =1 and PEFAMTYP_M=7;
where MD_Q02=1 or MD_Q06=1 or MD_Q14=1;
run;

The answer should be ID numbers 2 and 7 because they satisfy the all above conditions.

Appreciate if anyone could help. You can just ignore surveyfreq and wieghts what I need is to learn how to give conditions accurately.

Thanks

Mirisage
3 REPLIES 3
SASKiwi
PROC Star
Firstly with two WHERE statements, the last one will supercede the previous one so that one is the only active one.

If you want both to work, which your conditions confirm, then you need to change your second WHERE to WHERE ALSO. Alternatively you can combine the two into one like so:

where deprived =1 and PEFAMTYP_M=7
and (MD_Q02=1 or MD_Q06=1 or MD_Q14=1);
Cynthia_sas
SAS Super FREQ
Hi:
Just using PROC PRINT (since I don't know PROC SURVEYFREQ), both of these methods work for me. I find that I prefer the use of parentheses and logical operators over the use of WHERE ALSO, but in this instance they both produce the same results.

cynthia
[pre]

proc print data=HH;
title 'Method 1';
where (deprived =1 and PEFAMTYP_M=7)
and
(MD_Q02=1 or MD_Q06=1 or MD_Q14=1);
run;

proc print data=HH;
title 'Method 2';
where deprived =1 and PEFAMTYP_M=7;
where also MD_Q02=1 or MD_Q06=1 or MD_Q14=1;
run;

[/pre]
Mirisage
Obsidian | Level 7
Hi SASKiwi and Cynthia,

This is great!

All the codes provided by both of you worked elegantly and thank you very much.

Regards

Mirisage

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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