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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 571 views
  • 0 likes
  • 3 in conversation