I have a variable whose values are populated with likert scale responses (completely agree, agree, unsure, disagree, completely disagree). In some instances there are erroneous responses like "completely agree, agree" and "unsure, completely disagree". So the data might looks like this:
completely agree |
agree |
completely disagree |
agree |
unsure |
disagree |
unsure, completely agree |
unsure, disagree |
I'd like to create a new variable where completely agree = 1, agree = 2, unsure = 3, disagree = 4, completely disagree = 5, and everything else equals "." ----So the resulting data variable would have these values:
1 |
2 |
5 |
2 |
3 |
4 |
. |
. |
Can someone help me with the code here? I am thinking if, then, else, but I am not sure how to write it. Thanks!
That is fairly simple. I would use an infomat:
proc format;
invalue likert (upcase)
'COMPLETELY AGREE' = 1
'AGREE' = 2
'UNSURE' = 3
'DISAGREE' = 4
'COMPLETELY DISAGREE' = 5
other= .
;
run;
Data want;
set have;
value=input(response,likert.);
run;
I used the UPCASE option on the informat, as I assume the case of the text variables is not relevant (when values are read, all text is automatically converted to upper case before being evaluated).
Here are some video tutorials on the subject.
You'll need to go a step further because it appears you have multiple responses in the same field, such as "unsure, completetely agree". I usually recommend you go back to your survey software and change the export so each is in their own field.
Otherwise you can use COUNTW() to count the number of words, and SCAN() to extract each word and apply the logic.
@mt88 wrote:
I have a variable whose values are populated with likert scale responses (completely agree, agree, unsure, disagree, completely disagree). In some instances there are erroneous responses like "completely agree, agree" and "unsure, completely disagree". So the data might looks like this:
completely agree agree completely disagree agree unsure disagree unsure, completely agree unsure, disagree
I'd like to create a new variable where completely agree = 1, agree = 2, unsure = 3, disagree = 4, completely disagree = 5, and everything else equals "." ----So the resulting data variable would have these values:
1 2 5 2 3 4 . .
Can someone help me with the code here? I am thinking if, then, else, but I am not sure how to write it. Thanks!
That is fairly simple. I would use an infomat:
proc format;
invalue likert (upcase)
'COMPLETELY AGREE' = 1
'AGREE' = 2
'UNSURE' = 3
'DISAGREE' = 4
'COMPLETELY DISAGREE' = 5
other= .
;
run;
Data want;
set have;
value=input(response,likert.);
run;
I used the UPCASE option on the informat, as I assume the case of the text variables is not relevant (when values are read, all text is automatically converted to upper case before being evaluated).
Thanks very much. This did exactly what I needed.
Hi again,
I need anything that isn't "Completely Agree", "Agree", "Unsure", "Disagree", or "Completely Disagree" to be coded as missing, which it looks like this code does.
Thank you.
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.