BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DMP
Calcite | Level 5 DMP
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Okay! Smiley Happy

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;

--
Paige Miller

View solution in original post

17 REPLIES 17
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
DMP
Calcite | Level 5 DMP
Calcite | Level 5

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...:(

PaigeMiller
Diamond | Level 26

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'.

--
Paige Miller
DMP
Calcite | Level 5 DMP
Calcite | Level 5


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?

PaigeMiller
Diamond | Level 26

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;

--
Paige Miller
DMP
Calcite | Level 5 DMP
Calcite | Level 5

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
DMP
Calcite | Level 5 DMP
Calcite | Level 5

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?

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Reeza
Super User

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.

DMP
Calcite | Level 5 DMP
Calcite | Level 5

please see the attached doc.

thanks


Tables.jpg
PaigeMiller
Diamond | Level 26

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
--
Paige Miller
DMP
Calcite | Level 5 DMP
Calcite | Level 5

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

PaigeMiller
Diamond | Level 26

Okay! Smiley Happy

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;

--
Paige Miller

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
  • 17 replies
  • 1443 views
  • 0 likes
  • 4 in conversation