BookmarkSubscribeRSS Feed
lynnem
Calcite | Level 5

Hello,

I have a dataset that gives scores for each individual:

IDCat1Cat 2
2224511
5451551
5451534

I need two different levels of data from these scores:1, the frequencies of each (for cat1 and cat2), 1-5, which I easily get with Proc Freq, and 2) a calculated summary scores using the following equation and a variation (one for each of cat1 and cat2): (3+4)/(1+2+3+4)

1140.33140.33
2105725.08107125.42
351112.13158237.54
485920.38244157.93
5177342.074214100.00

If I export my Proc Freq then I have a nice dataset that looks like the above table, but I don't know how to get this into another dataset or table that calculates my final score.

Thoughts?

4 REPLIES 4
Reeza
Super User

Where is the 1+2+3+4 coming from?

lynnem
Calcite | Level 5

Those are the observation numbers. The calculation will look like this, filling in the frequencies for the observation numbers:

(511+859)/(14+1057+511+859) = 1370/2441 = 0.5612

Is there a way to automate that calculation so that I can export it and any other calculations into another dataset?

Reeza
Super User

I can't be 100% sure because you have two sets of sample data that don't match up and that's confusing me.

I think you may want to look into the multi label format and proc tabulate which will calculate these for you automatically.

This is under the assumption you want a standard proc freq, but then some pre defined categories as well,

For example, your data has values 1, 2, 3,4 and you want to count how many 1, 2, 3, 4 and 3/4 together.

Ksharp
Super User
data have;
input a b c d e;
cards;
1     14     0.33     14     0.33
2     1057     25.08     1071     25.42
3     511     12.13     1582     37.54
4     859     20.38     2441     57.93
5     1773     42.07     4214     100.00
;
run;
data var(keep=var1 var2);
 set have ;
 array x{4} _temporary_;
 array y{4} _temporary_;
 x{_n_}=b; y{_n_}=d;
 if _n_ eq 4 then do;
   var1=(x{3}+x{4})/sum(of x{*}) ;
   var2=(y{3}+y{4})/sum(of y{*}) ;
  output; stop;
 end;
run;


Xia Keshan

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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