okay the first image with the writing is the original from the survey. There were 4 possible answers, the right answer being:1 small apple.
I did what you recommended, and recoded it to what the second image is and if somebody answered wrong it would be 0 and if it was right, they got a 1.
In sas i imported the data. and then put the code listed above.
PROC TTEST DATA=work.import ALPHA=.05;
PAIRED pre*post;
RUN;
If that second photograph is how EXCEL shows your spreadsheet then the reason the variable is CHARACTER in SAS is because you made it character in EXCEL. That is what the little green triangles mean.
Typically what would happen is you import the raw data, you do not recode it manually. This is actually important as it allows for full scientific reproducibility and is an important part of the scientific process. Papers these days have been retracted because someone coded things as 1 or 0 and then someone else flipped that coding. Doing things manually is not the correct approach.
I would expect to see code that looks like the following:
*import raw data;
proc import datafile='myExcel.xlsx' out=rawData dbms=XLSX replace;run;
*clean up data;
data cleanData;
set rawData;
if Q3 in ('1 small apple') then Q3_Code = 1;
else Q3_Code=0;
/*rest of data cleaning required*/
run;
*Wrangle into format for pre-post, not sure because you have shown only the pre file;
data clean_long_data;
set cleanData;
/*merge cleanDatapre cleandatapost;*/
run;
*T-Test;
proc ttest data=clean_long_data;
....
run;
So far all you've shown is the first step. Which is the last step in what you need. Somewhere in that code above is where you would apply your fix for the data types.
Can you state your null hypothesis & alternative hypothesis precisely? Do you really want to have a test for each question or do you want to examine whether the % of correct answers across all respondents & all questions increased in the post survey?
Even though you can code responses as numeric (0 = incorrect, 1 = correct) for pre & post survey, you are really working with a categorical variable at the individual & question level.
You may find that a chi-sq test is more appropriate if examining each question with the cohorts being correct responders & incorrect responders on pre-test.
If you are evaluating the effectiveness of the intervention across all questions, you could measure the difference in pre & post test scores.
Example:
ID Pre-score Post-score Diff
1 75% 85% +10%
2 50% 65% +15%
...
Again, clearly stating your hypothesis would be very helpful
Most of us will not download XLSX (or other Microsoft Office) attachments, as they can be a security threat. The proper format to provide data is via SAS data step code (instructions).
My hypothesis is: based on the intervention, did the participants increase in knowledge in diabetic related information?
we are testing each question individually to see if it was significant... I was also told to change each question into a ditcotimous numerical format, but i'm not sure if i'm supposed too because the answers are categorical.
The first question in the survey was which food raises blood sugar levels the most? and examples of the answers is listed below....
i changed it to dichotomous format (1,0). There were 4 possible answers (1/3 cheddar cheese, 1 0z pork, 3oz hamburger, and the right one which is 1 small apple). 0 for wrong answers and 1 for correct answer.
but does that leave out important information?... can i still do the test test with it categorical answers?
--> for question 2 i find it a bit more confusing.. the question is; according to the Plate method , non starchy vegetables are how much of your plate?
i changed it to dichotomous format (1,0). There were 4 possible answers (the wrong ones are 1/4, 1/3 and 3/4. 1/2 is the correct answer). 0 for wrong answers and 1 for correct answer.
I also changed it to a ditcotimous format, but was told to change the answers to (.25,.33,.50,.75) instead and find the difference and then run the t test... but am not sure
why do I keep getting this error :
okay I changed the format fro just pre and post, and no I'm getting 2 errors:
ERROR:Variable Pre in list does not match type prescribed for this list.
ERROR:Variable Post in list does not match type prescribed for this list.
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)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Ready to level-up your skills? Choose your own adventure.