BookmarkSubscribeRSS Feed
Guerraje
Quartz | Level 8

I am working with survey data. I have been asked to create a new variable which is the sum of all of the variables below,  and then run a t-test so that we can use the standard deviation. 

I have tried to use proc means and proc summary but they are providing me with the sums of the rows now the sums of all the variables added up, so I can't quite figure out the right statements to use.

 

Thank you! 

 My example of proc summary code is here below, to show how I am trying to enter these variables 

 

PROC SUMMARY DATA= WORK.vaccine_hesitancy_data SUM PRINT; 
 VAR vaccinefactors1 vaccinefactors2 vaccinefactors3 vaccinefactors4 vaccinefactors5 vaccinefactors6 vaccinefactors7 vaccinefactors8 vaccinefactors9 vaccinefactors10 vaccinefactors11;
OUTPUT OUT= vaccinefactors
SUM= sum_of_vaccinefactors;
RUN; 
 
PROC TTEST ;
var vaccinefactors1 vaccinefactors2 vaccinefactors3 vaccinefactors4 vaccinefactors5 vaccinefactors6 vaccinefactors7 vaccinefactors8 vaccinefactors9 vaccinefactors10 vaccinefactors11;
CLASS VACCINEHESITANT; 
RUN;

 

 Total%Hesitant -1 %NotHesitant -0% 
 N = 7197 N = 281 N = 6916  
 n (%) p-value
What factors affect yout attitudes and thoughts about getting the COVID- vaccine? n (%)       
Politics6949.64%10035.59%5948.59%0.0001
The timeline in which the vaccines were developed and approved138319.22%20773.67117617.00%0.0001
The frequently changing messages around COVID-1991812.7617461.9274410.76%0.0001
Actions and opinions of my friends and family regarding the vaccine84111.694114.5980011.57%0.122
My trust in scientists 514771.52%5419.22509373.620.0001
My trust in doctors460163.93%5118.15455065.790.0001
My trust in public health officials389054.05%13347.33375754.320.0211
My own reading and research on coronavirus (COVID-19) vaccines439661.0816960.14422761.120.742
The country in which a vaccine is manufactured6629.20%227.836409.250.4179
The potential cost of a coronavirus (COVID-19) vaccine2843.95%41.422804.050.0267
Other factors 73410.28428.896509.40.0001
Total factors considered, mean (SD)       
12 REPLIES 12
sbxkoenk
SAS Super FREQ

Try this :

data have;
vaccinefactors1 = 7; 
vaccinefactors2 = 3;
vaccinefactors3 = 2.58; 
vaccinefactors4 = 1.20; 
vaccinefactors5 = 17; 
vaccinefactors6 = 18; 
vaccinefactors7 = 7; 
vaccinefactors8 = 7; 
vaccinefactors9 = 5; 
vaccinefactors10= 7; 
vaccinefactors11= 3;
output;
run;

data want;
 LENGTH sum_vaccinefactors 8;
 set have;
 sum_vaccinefactors=sum(of vaccinefactors1-vaccinefactors11);
run;
/* end of program */

Koen

Guerraje
Quartz | Level 8
We have 11 choices a person could have selected as a reason for their vaccine hesitancy. We decided we want to get the sum of all of them now and create a new variable we could title it:
"vaccinefactor"
which is just the total of all the data.
Guerraje
Quartz | Level 8
Is there a way to calculate the sum and give that sum the variable name of "vaccinefactor" so that I can then use that variable attached to that sum to use later?
Reeza
Super User
DATA need;
   set WORK.vaccine_hesitancy_data; 
   VaccineFactor = sum(of vaccinefactors1-vaccinefactors11);
run;
Kurt_Bremser
Super User

@Guerraje wrote:
We have 11 choices a person could have selected as a reason for their vaccine hesitancy. We decided we want to get the sum of all of them now and create a new variable we could title it:
"vaccinefactor"
which is just the total of all the data.

The suggested codes do exactly that, you only need to change the name of the target variable.

Guerraje
Quartz | Level 8

When running that code, I happen to get an error that my variable is not found. I am attaching my code and my log.

 

Thank you 

Screen Shot 2021-10-27 at 1.21.17 PM.png

Reeza
Super User
I'm assuming your values are hardcoded for us? To show the screenshot? Otherwise you're doing something very inefficient and possibly incorrect here.
ballardw
Super User

@Guerraje wrote:
We have 11 choices a person could have selected as a reason for their vaccine hesitancy. We decided we want to get the sum of all of them now and create a new variable we could title it:
"vaccinefactor"
which is just the total of all the data.

Summing this coding sounds like an exercise in adding up football team names.

 

What exactly do some of the "numbers" mean? Even with a rating scale adding responses from multiple responses from the scale does not mean that a total of 12 for one person is anything at like a total of 12 for a different respondent.

ballardw
Super User

It might not hurt to provide a very small example of something and show the expected results from that.

 

I think that you may need to sum the variables in each row such as in a data step

DATA need;
   set WORK.vaccine_hesitancy_data; 
   VacTot = sum(of vaccinefactors1-vaccinefactors11);
run;

HOWEVER, there is a concern with this data starting from a SURVEY. Does your data include weights for the observations? If so you may need to use another approach to use the weights properly after getting that total.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 12 replies
  • 2296 views
  • 0 likes
  • 5 in conversation