BookmarkSubscribeRSS Feed
rikhan
Calcite | Level 5

Hi,

is there a way to separate the sub levels of a variable so that the sub levels are in rows and the variables are as columns.  To illustrate what i mean, attached is a picture. First picture is in sas, second picture is what i would like to do in sas.  Apologies if this is covered else where, but i have literally searched everywhere without success.  I am guessing it is called something else since these seems like a pretty simple/common approach to creating a table.  Below is the code. Any guidance would be greatly appreciated!  thanks!

tab.png

proc tabulate data=scores;

class Q1 Q2;

table N,

Q1 Q2;

run;

6 REPLIES 6
Reeza
Super User

First picture can't be your data in SAS, that's the report. You need to show what your actual data looks like.

Unless you have them backwards?

The word you're looking for is transpose though:

SAS Learning Module: How to reshape data wide to long using proc transpose

SAS Learning Module: Reshaping wide to long using a data step

rikhan
Calcite | Level 5

Apologies, yes the data looks like in the picture below

q.png

Reeza
Super User

TThat's already your second picture? Or do you need it summarized/aggregated somehow?

rikhan
Calcite | Level 5

Yup exactly, I need the raw data (pic 3) summed like it is in pic 1 and pic 2.   the first picture shows the counts for the subcategories within a variable (categorical) from sas, pic 2 is the format i would like it in.  So for example, the possible choices for Q1 are 1 - 5.  8 people responded 1, 7 people ressponded 2 etc.  So It shows the counts for each choice.  The third picture is just the raw data.  For now what i do is get counts, export it to excel and create pivot tables to achieve this.  But Im wondering if htere is a quicker way to do this.

Reeza
Super User

Yes, but the data you showed only shows a portion of your problem. It would help if you would illustrate the full problem with sample data in the text here so we can use it directly rather than type it out. The general solution will be along the lines of query, with a specific group by clause and then sum or count the values as required. That will create the data set and then you can easily print out that data set using the LIST task

KenDodds
Calcite | Level 5

You are wanting two univariate summaries.

One way is to put all the results into a single variable:


data allscores;  * or use proc transpose;

   SET scores;

   q='q1'; result=q1; output;

   q='q2'; result=q2; output;

proc tabulate data=allscores;

  class q result;

  table result,q ;

  run;

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1917 views
  • 0 likes
  • 3 in conversation