BookmarkSubscribeRSS Feed
vishalrajpoot3
Obsidian | Level 7

I have below table with variables and their labels and there are multiple observations against each value/labels.

 

VariableValueLabel
Pre_11Use every day
Pre_12Use some days
Pre_13Don't use, but have tried in the past
Pre_14Heard a lot & never tried
Pre_15Heard a little & never tried
Pre_16Never heard of it
Pre_21Use every day
Pre_22Use some days
Pre_23Don't use, but have tried in the past
Pre_24Heard a lot & never tried
Pre_25Heard a little & never tried
Pre_26Never heard of it

 

How can I get below output using proc freq:

 

Q225 
pre_1_2FrequencyPercentCumulative
Frequency
Cumulative
Percent
Use every day306.32306.32
Use some days9820.6312826.95
Not at all34773.05475100.00

 

 

 

 

 

11 REPLIES 11
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
vishalrajpoot3
Obsidian | Level 7

 This is label for the variable.

PaigeMiller
Diamond | Level 26

Okay, so show us a portion of the actual data.

--
Paige Miller
vishalrajpoot3
Obsidian | Level 7

@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".

 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
vishalrajpoot3
Obsidian | Level 7

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_1Pre_2
Use some daysHeard a little & never tried
Use every dayUse every day
Never heard of itDon't use, but have tried in the past
Heard a lot & never triedHeard a lot & never tried
Heard a little & never triedNever heard of it
Don't use, but have tried in the pastUse some days

 

so, using proc freq on above dataset can I get below output:

 

pre_1_2FrequencyPercentCumulative
Frequency
Cumulative
Percent
Use every day306.32306.32
Use some days9820.6312826.95
Not at all34773.05475100.00

 

Tom
Super User Tom
Super User

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;
vishalrajpoot3
Obsidian | Level 7
will it not increase the no of observation?
Tom
Super User Tom
Super User

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.

vishalrajpoot3
Obsidian | Level 7
for both the variables, rules are like: value 1 (use every day) and 2 (use some days) should be displayed as it is and rest all values from 3 to 6 should be clubbed in single category "Not at all".
can you please help me with the code?
Reeza
Super User

Your problem as I understand it:

  • 2 variables with the same labels/values
  • Would like a summary of the values across both columns in one summary table
  • With labels applied, not raw values

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

 

 

 

 

 


 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 373 views
  • 0 likes
  • 4 in conversation