Hello, I have a question
i have data from a survey... it was knowledge based... and there is pre and post data.
it is a multiple choice questions, with 4 answers and only one is correct.
how can i run a t test with this data?
Here is a quick way to make sure your variable names conform to SAS naming conventions when importing data:
1. Go to preference in SAS Studio
2. On the Tables Tab, update the Polices: SAS variable name policy = V7 & SAS member name policy = COMPATIBLE
3. Click Save
This will force variables to be compatible with SAS naming convention (example:. replace spaces with underscores)
the hypothesis changes for each question, for example question 1 was which food raised blood sugar levels the most... in that case answers were given (the right answer is 1 small apple) and we are comparing the increase in wright answers.
Question 2 is what non-starchy vegetables are how much of your plate? with the correct answer being 1/2.
Then first convert your data to numeric values that can be analyzed.
I'm assuming the overall question then is how many people get the answers correct before and after? So the hypothesis is actually the same across all questions if you generalize it a bit more with each question being different.
I would probably restructure my data to be something like:
User Question PreAnswerCorrect PostAnswerCorrect 1 1 1 1 1 2 0 1 1 3 0 1 1 4 1 1 2 1 1 1 2 2 1 0 2 3 0 0 2 4 1 0
Then you can use PROC TTEST as in the example above:
proc sort data = have;
by question;
proc ttest data = have;
by Question;
paired PreAnswerCorrect * PostAnswerCorrect;
run;
@ecampos2 wrote:
the hypothesis changes for each question, for example question 1 was which food raised blood sugar levels the most... in that case answers were given (the right answer is 1 small apple) and we are comparing the increase in wright answers.
Question 2 is what non-starchy vegetables are how much of your plate? with the correct answer being 1/2.
thank you much....the data you provided had 4 rows.... wouldn't it only have 2 one for pre and one for post?
I tried to do what you suggested and for wrong answers i put 0 and right answers i put 1.... did we need to analyze each possible answer that was given?
pre post
0 1
1 1
1 1
1 1
1 1
0 1
1 1
0 1
0 0
1 1
1 1
1 1
0 0
1 1
1 1
1 1
1 1
1 1
0 0
1 1
0 0
1 1
0 0
1 1
0 0
0 0
1 0
0 1
0 0
1 1
0 0
0 1
0 0
0 1
1 1
1 1
1 1
1 1
1 0
1 1
0 0
@ecampos2 wrote:
thank you much....the data you provided had 4 rows.... wouldn't it only have 2 one for pre and one for post?
I tried to do what you suggested and for wrong answers i put 0 and right answers i put 1.... did we need to analyze each possible answer that was given?
pre post 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0
This doesn't indicate which subject is being evaluated, and it doesn't indicate what question was correct, or not. So I like the data layout from @Reeza
Also, please don't tell us what you tried doesn't work and provide no other information, because we don't know what you tried. Show us the code you tried, and the result.
No, it would not have just two.
I assume you measured pre and post on the same person by the way. How would you identify which record goes with which person? That's why you need the ID.
Then adding Question in allows you to do all questions at once by adding in the BY QUESTION portion. Those are the two additional variables that make this easier to analyze.
Do you absolutely require them? No. Will they make your life easier and help make sure you don't mistakes? Yes. Do they make the work easier? Yes. Otherwise, how will you tell each data set apart for each question? You'll have 4 data sets (1 for each question instead) and 4 sets of code. If you need to change something one place you'll now have to change it in 4 places.
did we need to analyze each possible answer that was given? did we need to analyze each possible answer that was given?
Depends on if you want to include that data in your analysis. If you do, then yes. You can do that using a program though, not manually.
Thank everyone so much!
For some reason Im still not getting a t- test. I'm getting this error on SAS:
ERROR: Variable pre in list does not match type prescribed for this list.
I really don't understand how does sas knows what question is right or wrong?
I also changed the data format to what rezza suggested. I row patient id, 1 row question number, and pre and post response. I imported the doc i attached (question 1 pre) and then put the code you suggested
proc sort data = work.import;
by question;
proc ttest data = work.import;
by Question;
paired pre*post;
run;
@ecampos2 wrote:
Thank everyone so much!
For some reason Im still not getting a t- test. I'm getting this error on SAS:
ERROR: Variable pre in list does not match type prescribed for this list.
Usually this means a variable is character when it should be numeric.
From your file attached, I'm guessing PRE is a character variable when it should be numeric (based on alignment, just a guess).
I really don't understand how does sas knows what question is right or wrong?
Didn't you code the data as 1 being correct, 0 being wrong?
Otherwise how did you code your 0/1 in the data shown?
Yes so the question on the survey was a knowledge based question, "Which food raised blood sugar level the most?". There was 4 possible answers 1/3 cheddar cheese, 1 oz pork bacon, 3 oz hamburger patty, and 1 small apple. (The correct answer was 1 small apple)
I put 0 for people who answered 1/3 cheddar cheese, 1 oz pork bacon, or 3 oz hamburger patty, and 1 for people who answered the correct answer; 1 small apple.
Also how could i change my pre to be a character not numeric?
@ecampos2 wrote:
Also how could i change my pre to be a character not numeric?
You want numeric, not character.
Go back and fix how you calculated it. Show that code and we can help you fix it. If you put the 0/1 in quotes that's one way to have created them as character.
@ecampos2 wrote:
Also how could i change my pre to be a character not numeric?
okay i have attached the data in the format you recommended (question 1 pre.xlsx).
I first imported the doc in sas.
once downloaded my sas code was:
PROC TTEST DATA=work.import ALPHA=.05;
PAIRED pre*post;
RUN;
Then it gives me the error: ERROR: Variable pre in list does not match type prescribed for this list.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Select SAS Training centers are offering in-person courses. View upcoming courses for: