I have below table with variables and their labels and there are multiple observations against each value/labels.
Variable | Value | Label |
Pre_1 | 1 | Use every day |
Pre_1 | 2 | Use some days |
Pre_1 | 3 | Don't use, but have tried in the past |
Pre_1 | 4 | Heard a lot & never tried |
Pre_1 | 5 | Heard a little & never tried |
Pre_1 | 6 | Never heard of it |
Pre_2 | 1 | Use every day |
Pre_2 | 2 | Use some days |
Pre_2 | 3 | Don't use, but have tried in the past |
Pre_2 | 4 | Heard a lot & never tried |
Pre_2 | 5 | Heard a little & never tried |
Pre_2 | 6 | Never heard of it |
How can I get below output using proc freq:
Q225 | ||||
pre_1_2 | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
Use every day | 30 | 6.32 | 30 | 6.32 |
Use some days | 98 | 20.63 | 128 | 26.95 |
Not at all | 347 | 73.05 | 475 | 100.00 |
Please clarify this part:
I have below table with variables and their labels
Is the column named LABEL the name of an actual variable named LABEL, or is it an actual label for a variable?
This is label for the variable.
Okay, so show us a portion of the actual data.
@PaigeMiller The table I have pasted above is actual data and below one is the output of proc freq. In output both the variable (pre_1 and pre_2) grouped as pre_1_2 and last 4 value of both the variables grouped as "Not at all".
You can't get the PROC FREQ output from the input data set without re-arranging the data. There is no variable Pre_1_2 in your original data set, but there is in the output data set. And because of this, it isn't even clear to me how you derive the output table if you were to do this by pencil and paper. Please explain the steps between the input data and the output table, step-by-step, so I can see what you are doing.
please ignore the previous information provided.
So, I have a data set abc and it has two variable pre_1 and pre_2 with values from 1 to 6. All the 6 values has format as in below output table :
Pre_1 | Pre_2 |
Use some days | Heard a little & never tried |
Use every day | Use every day |
Never heard of it | Don't use, but have tried in the past |
Heard a lot & never tried | Heard a lot & never tried |
Heard a little & never tried | Never heard of it |
Don't use, but have tried in the past | Use some days |
so, using proc freq on above dataset can I get below output:
pre_1_2 | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
Use every day | 30 | 6.32 | 30 | 6.32 |
Use some days | 98 | 20.63 | 128 | 26.95 |
Not at all | 347 | 73.05 | 475 | 100.00 |
Put the data into ONE variable. Then run PROC FREQ.
data tall;
set have;
pre_1_2 = pre_1;
output;
pre_1_2=pre_2;
output;
run;
proc freq data=tall;
tables pre_1_2;
run;
Yes. It will double the number of observations. Which is what you need to be able to produce the table you showed.
If you wanted to produce such a table without increasing the total N you would need to classify each individual observation into just one category. I could be done but you would need to decide what the rules are.
Your problem as I understand it:
If that's correct the solution is to:
Or you can do it in in a slightly different order:
If you need help with code, please provide sample data in the form of a data step.
@vishalrajpoot3 wrote:
I have below table with variables and their labels and there are multiple observations against each value/labels.
Variable Value Label Pre_1 1 Use every day Pre_1 2 Use some days Pre_1 3 Don't use, but have tried in the past Pre_1 4 Heard a lot & never tried Pre_1 5 Heard a little & never tried Pre_1 6 Never heard of it Pre_2 1 Use every day Pre_2 2 Use some days Pre_2 3 Don't use, but have tried in the past Pre_2 4 Heard a lot & never tried Pre_2 5 Heard a little & never tried Pre_2 6 Never heard of it
How can I get below output using proc freq:
Q225 pre_1_2 Frequency Percent Cumulative
FrequencyCumulative
PercentUse every day 30 6.32 30 6.32 Use some days 98 20.63 128 26.95 Not at all 347 73.05 475 100.00
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.