BookmarkSubscribeRSS Feed
Watkins155
Calcite | Level 5
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.
 
2 REPLIES 2
Reeza
Super User

You have the variables names incorrect. 

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

SuzanneDorinski
Lapis Lazuli | Level 10

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 1354 views
  • 1 like
  • 3 in conversation