turn on suggestions

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
- /
- ODS and Base Reporting
- /
- How to customise the output?

Topic Options

- Subscribe to 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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-08-2013 10:18 AM

I am using the proq freq to get the occurences for certain values that happens for each of the 4 variable of interest. These 4 fields(variables) have the same sets of values. I want to get in my output only the frequencies for these values only. How can I do this if I am looking at all 4 variables at the time.

Example:

I am looking at variables:

A (can take values a,b,c.d,e)

B (can take values a,b,c.d,e)

C( can take values a,b,c.d,e)

D( can take values a,b,c.d,e)

I want **only** the frequency of value "c" occuring in all 4 vb. (A,B,C,D) in the output. how can I do this?

Thank you!

Accepted Solutions

Solution

02-08-2013
01:09 PM

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

02-08-2013 01:09 PM

Okay!

So here's the problem. PROC FREQ doesn't do sums.

Here is a multi-step program to get what you want. Maybe there is a shorter way, but this is how I would do it

proc freq data=whatever;

by somevariable;

tables a/noprint out=var_a_freq;

tables b/noprint out=var_b_freq;

tables c/noprint out=var_c_freq;

tables d/noprint out=var_d_freq;

run;

data all;

set var_a_freq(where=(a='c')) var_b_freq(where=(b='c')) var_c_freq(where=(c='c')) var_d_freq(where=(d='c'));

by somevariable;

run;

proc means data=all sum;

by somevariable;

var count;

run;

All Replies

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

02-08-2013 10:27 AM

Have PROC FREQ create an output data set, then select only the values where the variable has value c

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

Posted in reply to PaigeMiller

02-08-2013 10:35 AM

That is exactly ewhat I am doing the problem is the the variable(s) has about 1000 values and if I look at all 4 vb at once it will give me the freq for the occurence of one value but also the occurence of the values for the other 3 vb when one vb has the value of interest. I mean when I have vb A= "c", vb Bwill be ="a" and C="d" and so for. When I do Proq Freq it gives me for var A let's say, the frequence for value"c" but also frequences fo all other values when the other var (B,C,D) are equal "c". I am doing it in excel but is to time consuming and it should be a smarter way to do this in SAS only I don't know it...

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

02-08-2013 10:40 AM

It would help to see your code.

This should be nothing more difficult than in a DATA step after PROC FREQ, selecting only the case where A='c' and B='c' and C='c' and D='c'.

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

Posted in reply to PaigeMiller

02-08-2013 10:48 AM

here's the code I use:

PROC FREQ DATA = SASUSER.MY_08DATA_Feb7

ORDER=INTERNAL;

Title’’;

BY FACILITY_PROV_CODE;

TABLES MAIN_PROBLEM OTHER_PROBLEM_1 OTHER_PROBLEM_2 OTHER_PROBLEM_3 OTHER_PROBLEM_4/

missing

NOROW

NOCOL

NOPERCENT

NOCUM

SCORES=TABLE

ALPHA=0.05;

where (MAIN_PROBLEM = 'T424' or OTHER_PROBLEM_1 = 'T424' or OTHER_PROBLEM_2 = 'T424' OR OTHER_PROBLEM_3 = 'T424' or OTHER_PROBLEM_4 ='T424') and AGE_CODE='Y' and AGE_UNITS LT 55;

RUN; QUIT

what do you mean by selecting these in a data step after proq freq?

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

02-08-2013 10:53 AM

proc freq data=whatever;

by facility_prov_code;

tables a/out=var_a_freq;

run;

data var_a_freq;

set var_a_freq;

where a='c';

run;

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

Posted in reply to PaigeMiller

02-08-2013 11:14 AM

This is giving me the occurence of "c" only as value of variable A. But if I have to add up the occurences of "c" as values of A and B and C And D?

It's like adding the occurences of "c" for the cases specified in where.

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

02-08-2013 11:17 AM

I request at this time that you provide much more specificity about what the desired output is. As in, **give an example of the output you want**. Your words do not convey to me exactly what you are trying to achieve.

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

Posted in reply to PaigeMiller

02-08-2013 11:44 AM

with my code I get 4 tables (one for each variable) that are each hundreds of items long , containing the frequencies for each value occuring when one of the condition under where clause is true . In order to get my counts for the value of interest ("c") occuring in all 4 vb. I manually combine these 4 output tables and sort the combined table in order to get the 4 values of "c"-frequency (one for each variable that I am monitoring).

How can I do this with SAS so that I am not spending hours to set up these excel tables to extract only the occurences of 'c' in all 4 variables?

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

02-08-2013 11:47 AM

Not what I asked for.

I don't want a word description. I don't think I can work from your word descriptions.

I want to see an example of the resulting table that you wish to get.

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

Posted in reply to PaigeMiller

02-08-2013 12:08 PM

Look at PG's solution and the table that gets outputted, OWF. What you want is in that table.

I agree with Paige however, your question is unclear, so the suggestions your getting are guesses. Clarify your request. My guess is you're looking for the total C rather than the count of any cell, so you're actually looking for a row or column total that you would see in proc freq. You can get that in the solution PG has posted.

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

Posted in reply to PaigeMiller

02-08-2013 12:10 PM

please see the attached doc.

thanks

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

02-08-2013 12:50 PM

I don't see how the "what you'd like to get" relates to the tables you are currently getting, nor do I see how the "what you'd like to get" relates to your original problem description.

Is the "what you'd like to get" a sum of frequencies? That's my guess, but the word "sum" (and its synonyms) have not appeared in this discussion so far.

So let's take this a step further

Is the desired output any one of the following?

- frequency that simultaneously A='C' and B='C' and C='C' and D='C'
- frequency A='C' + frequency B='C' + frequency C='C' + frqeuency D='C'
- something else

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

Posted in reply to PaigeMiller

02-08-2013 01:01 PM

I am so sorry for not being clear on this. Yes this is what I wanted: the sum of the frequencies as you described

- frequency A='C' + frequency B='C' + frequency C='C' + frqeuency D='C'

(and these frequencies are calculated under the conditions in where clause in my code)

and I tried the code PG sent but it does not work

Solution

02-08-2013
01:09 PM

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

02-08-2013 01:09 PM

Okay!

So here's the problem. PROC FREQ doesn't do sums.

Here is a multi-step program to get what you want. Maybe there is a shorter way, but this is how I would do it

proc freq data=whatever;

by somevariable;

tables a/noprint out=var_a_freq;

tables b/noprint out=var_b_freq;

tables c/noprint out=var_c_freq;

tables d/noprint out=var_d_freq;

run;

data all;

set var_a_freq(where=(a='c')) var_b_freq(where=(b='c')) var_c_freq(where=(c='c')) var_d_freq(where=(d='c'));

by somevariable;

run;

proc means data=all sum;

by somevariable;

var count;

run;