Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- how to give 'where' condition twice in a one code ...

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-09-2010 06:17 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Mirisage

06-09-2010 09:23 PM

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);

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);

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Mirisage

06-09-2010 09:27 PM

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]

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]

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Cynthia_sas

06-09-2010 10:38 PM

Hi SASKiwi and Cynthia,

This is great!

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

Regards

Mirisage

This is great!

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

Regards

Mirisage