Hi everyone.
I have twenty questions: Q1 - Q20. The responses are in the form of Likert scale.
1 – “strongly agree”
2 – “somewhat agree”
3 – “neither agree no disagree’
4 – “somewhat disagree’
5 – “ strongly disagree”
How do I do reverse coding for all questions at one time?
Thanks for your help.
This site:
https://www.theanalysisfactor.com/easy-reverse-code/
is suggesting a neat subtraction trick:
Data yourdata;
Set yourdata;
NewVariable = 6 – OldVariable;
Run;
so
q1recode = 6 - q1;
If q1 is a 5, q1recode becomes a 1.
If q1 is a 1, q1recode becomes a 5.
Use arrays and math.
data want;
set have;
array _Q(20) Q1-Q20;
do i=1 to dim(_Q);
_q(i) = 6 - _q(i);
end;
run;
Not sure what your trying to do. As far as I understood here is my tip:
If your scale is in continuous sequence then
data test;
input num;
datalines;
1
2
3
4
5
;
run;
proc sql;
select *,(max(num)+1)-num as new_num
from test;
quit;
If not continuous then,
data test;
input num;
datalines;
1
2
4
5
;
run;
proc sort data=test out=reverse_test;
by descending num;
run;
data reverse;
merge test reverse_test(rename=(num=new_num));
run;
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 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.