BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mt88
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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).

View solution in original post

5 REPLIES 5
Reeza
Super User

Here are some video tutorials on the subject. 

 

https://video.sas.com/detail/videos/sas-analytics-u/video/4573016759001/performing-conditional-logic...

 

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!


 

 

s_lassen
Meteorite | Level 14

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).

mt88
Calcite | Level 5

Thanks very much. This did exactly what I needed.

Reeza
Super User
Check the last two records of your input data, if it matches your example data posted. This would not handle those cases.
mt88
Calcite | Level 5

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 978 views
  • 1 like
  • 3 in conversation