Write and run SAS programs in your web browser

Code Error for Calculating Weighted Means

Reply
New Contributor
Posts: 3

Code Error for Calculating Weighted Means

[ Edited ]
Good afternoon,
 
I am trying to compute weighted means for my dataset. Attached is a screenshot of the dataset I'm working with. Below is the code I am using and the error that I am getting. Essentially I am computing the means of the prevalence weighted by the sample size and I want it to be done by parasite class.
 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
59
60 proc means data=ANTH.capprevanth mean median;
61 class parasites ;
62 weight samplesize2 ;
ERROR: Variable SAMPLESIZE2 not found.
63 var prevalence ;
64 run;
 
When I tried to type in the name with spaces, I receive the following error:
 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
59
60 proc means data=ANTH.capprevanth mean median;
61 class parasites ;
62 weight sample size 2 ;
____
22
202
ERROR: Variable SAMPLE not found.
ERROR 22-322: Expecting ;.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
63 var prevalence ;
64 run;
 
Any ideas how I can solve this? I'm thinking it is a small error, but I am not sure what it is. Thank you.
 
Super User
Posts: 19,855

Re: Code Error for Calculating Weighted Means

Posted in reply to Watkins155

You have the variables names incorrect. 

Run a PROC CONTENTS and see the exact variable names you need to use. 

Frequent Contributor
Posts: 89

Re: Code Error for Calculating Weighted Means

Posted in reply to Watkins155

From your screen shot, it looks like you are using SAS Studio, viewing column labels, like this example:

 

SAS Studio data set viewer showing column labelsSAS Studio data set viewer showing column labels

 

As Reeza mentioned, you could run PROC CONTENTS on your data set.  Or you could switch the view to column names, as shown below:

 

SAS Studio data set viewer showing column namesSAS Studio data set viewer showing column names

Ask a Question
Discussion stats
  • 2 replies
  • 187 views
  • 1 like
  • 3 in conversation