BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sasgorilla
Pyrite | Level 9

I have a data set where a "count" variable means there are X numbers of individuals with the preceding characteristics in that observation. See below as an example. In the first observation, 3 means there are three 24 year-old males who scored 100. 

 

data sample;
input age score sex$ count;
datalines;
24	100 M 3
25	95 F 2
25	97 M 2
20	86 M 3
30	100	F 2	
;
RUN;

Let's say I wanted to do a proc freq of sex * score.

 

PROC FREQ data=sample;
     TABLES sex*score;
run;

Is there a way to call out the actual number of each sex achieving each score by using the "count" value for each observation? My code above counts only one sex per row, obviously. 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use a WEIGHT statement.

 

The WEIGHT statement names a numeric variable that provides a weight for each observation in the input data set. The WEIGHT statement is most commonly used to input cell count data. 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Use a WEIGHT statement.

 

The WEIGHT statement names a numeric variable that provides a weight for each observation in the input data set. The WEIGHT statement is most commonly used to input cell count data. 

sasgorilla
Pyrite | Level 9

That is exactly what I was looking for. Thanks!

ballardw
Super User

Some procedures other than Proc Freq support both Weight and Freq statements.

Consider if you are asked for the Mean and Standard deviation of the Scores.

You might try:

Proc means data=sample;
   title "With WEIGHT statement";
   var score;
   weight count;
run;

Which shows a result of

With WEIGHT statement
Analysis Variable : score
N Mean Std Dev Minimum Maximum
5 95.1666667 9.6910612 86.0000000 100.0000000

 

But the N shown does not match the "count" that would be expected.

So consider:

Proc means data=sample;
   title "With FREQ statement";
   var score;
   Freq count;
run;

with a result:

With FREQ statement

Analysis Variable : score
N Mean Std Dev Minimum Maximum
12 95.1666667 5.8439298 86.0000000 100.0000000

Now N looks like the total of Count and the Standard Deviation here uses the larger N in the calculation.

 

For most procedures that have both Weight and Freq statements you would want the Freq option to identify such a count variable.

 

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1363 views
  • 1 like
  • 3 in conversation