Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating Mean on a character field count 1

Status
Not open for further replies.

jen9814

Technical User
Nov 5, 2002
35
US
I am attempting to calculate a mean on a character field count. I would like to have the average number of products sold by person. So far I have the count of products sold by person using the following:

proc means data=policy_count N;
class name;
var policy_num;
run;

Now, how do I get the overall average? Any help would be appreciated. Thanks.
 
proc means data=policy_count N MEAN;
class name;
var policy_num;
run;


I think this is all you need.

dje
 
Not sure my first response was what you were looking for.
You may find it useful to create a file with the stats info and then you can report on several aspects of the data with other SAS procs, etc. Example below shows one method.




proc means data=policy_count N MEAN min max sum noprint;
class name;
var policy_num;
output out=stats
n= NA
mean = XA
min = MINA
max = MAXA
sum= SUMA ;
run;

data report;set stats;

proc means;var na;run;
 
The following code only gives the individual means. I need the overall for the entire data set.
proc means data=policy_count N MEAN;
class name;
var policy_num;
run;

The next code gives me an overall mean but it includes the column names in the count and the mean is incorrect.
 
Do you have some sample data that you can include?
 
Below is some dummy data to illustrate.

Name Policy Num
Jones 123
Jones 124
Jones 125
Smith 126
Johnson 127
Johnson 128
Davis 129
Davis 130
Davis 131
Davis 132
Davis 133
Davis 134
 
Below is some dummy data to illustrate.

Name Policy Num
Jones 123
Jones 124
Jones 125
Smith 126
Johnson 127
Johnson 128
Davis 129
Davis 130
Davis 131
Davis 132
Davis 133
 
Take the statement 'class name' out. You can use some 'BY' vars to get the means by that group.
ex.
proc means data=policy_count N MEAN;
by name;
var policy_num;
run;

If you want to use this data (in another seg. of code) why not use the 'output' keyword and get the stats in into dataset form.
Klaz
 
the request as written together with the sample data do not make sense. what does "average number of products sold by person" mean? with the sample data provided one can derive the count but an average is meaningless since there is no denominator to average with.

otoh, if you had variables for, say, name, month, and policy number then you could find the average number of policies per person per month.

it takes a two step process. use PROC SUMMARY to create a sum by person and month like so.

PROC SUMMARY DATA=POLICY_COUNT NWAY;
CLASS NAME MONTH;
OUTPUT OUT=POLICY_SUMMARY;
RUN;

now you have some numbers you can average by person, namely the number of policies sold by month. you can use PROC MEANS to produce the output (although i like TABULATE, so my example uses it instead).

PROC TABULATE DATA=POLICY_SUMMARY NOSEPS FORMAT=8.1;
CLASS NAME;
VAR _FREQ_;
TABLE NAME ALL,
MEAN*_FREQ_='POLICIES SOLD';
RUN;

this should work for you. best of luck!

** mp **
 
Sorry for the confusion. I will try to clarify what I would like to do. I would like to find out the overall average number of policies (variable policy num) per household (variable name). In the first set of sample data Jones has three policies, Smith 1 policy, Johnson 2 policies, and Davis 6 policies. The overall average is 3. This is what I am trying to find a way to calculate. I am not trying to calculate by a date variable because I have previously restricted the dates to only include the dates I am looking for. I hope this makes what I would like to do more clear.
 
data policy_count; infile cards;
input Name $7. Policy_Num 6.0;
cards;
Jones 123
Jones 124
Jones 125
Smith 126
Johnson 127
Johnson 128
Davis 129
Davis 130
Davis 131
Davis 132
Davis 133
;


proc means data=policy_count N MEAN min max sum noprint;
class name;
var policy_num;
output out=stats
n= NA
mean = XA
min = MINA
max = MAXA
sum= SUMA ;
run;

data report;set stats;
* not sure why values for a blank name results from using
the code above but easy to adjust I normally dont use the class statement much;

if name= " " then delete;

proc print;run;
proc means;var na;run;


 
The code works perfect!! Thanks to all of you that responded. This will help me a great deal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top