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

As in the attachment, I have multiple "pair_" variables. 

I used the following code to get freqency on the categories of each "pair_:" variable

 

proc freq data=have;
table Pair_:;
run;

 

In the "Results Viewer" I got many freq tables of each "Pair_:" variable.

For example, "pair_1_2" looks like following

 

Pair_1_2 Frequency Percent Cumulative
Frequency
Cumulative
Percent
different resp and both wrong 35 17.50 35 17.50
different resp and one of them 37 18.50 72 36.00
same resp and both correct 118 59.00 190 95.00
same resp and both wrong 10 5.00 200 100.00

 

Now I want to stack all of the freq table into One table, then  using the stacked freq table, I want to divided "frequency" by 149, and get a "new_pct" variable, the results I wanted will look like the following:

 

  category freq   pct_new
  different resp and both wrong 35 149 0.23
  different resp and one of them 37 149 0.25
pair_1_2 same resp and both correct 118 149 0.79
  same resp and both wrong 10 149 0.07
  different resp and both wrong 42 149 0.28
         
pari_1_3 different resp and one of them 34 149 0.23
  same resp and both correct 114 149 0.77
  same resp and both wrong 10 149 0.07

 

What's the efficient SAS code to stack all freq tables and then get the  final wanted table ? Any help would be much appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Actually...disregard the previous message, you need this one, since you're only looking at one variable at a time. For some reason I thought you were looking at two. This is an example of exactly what you want.

 

https://gist.github.com/statgeek/e0903d269d4a71316a4e

View solution in original post

2 REPLIES 2
Reeza
Super User

Actually...disregard the previous message, you need this one, since you're only looking at one variable at a time. For some reason I thought you were looking at two. This is an example of exactly what you want.

 

https://gist.github.com/statgeek/e0903d269d4a71316a4e

superbug
Quartz | Level 8

@Reeza 

Many thanks for the information!!

I very much appreciate your help!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2128 views
  • 1 like
  • 2 in conversation