BookmarkSubscribeRSS Feed
ssatyal
Calcite | Level 5

I import a data set from SPSS but the responses are displayed as texts. I want them to be recoded into values that correspond to Strongly Agree = 7, Agree = 6.................. and Strongly Disagree = 1

 

 


Untitled.png
2 REPLIES 2
Reeza
Super User

Please post your code as TEXT not as an image, otherwise we need to type out your code to make suggestions.

 

 

Text needs to be quoted when used in comparisons, otherwise it's looking for a variable. Quote the characters in your recode statement.

ballardw
Super User

You cannot change the variable type from character to numeric for an existing SAS variable. Best, for  a number of reasons would be recode into a new varaible that would be numeric. I prefer to recode using a custom informat for things like this, especially when there are many variables. Here is a brief example creating an informat and manipulating some dummy data.

 

proc format library=work;
invalue Likert (upcase)
"AGREE"=6
"AGREE SOMEWHAT"=5
"NEUTRAL" = 4
"DISAGREE SOMEWHAT"=3
"DISAGREE" = 2
;
RUN;

/* creating some example data*/
Data have;
   infile datalines dlm=',';
   informat Q10_1 Q10_2 $20.;
   input Q10_1 Q10_2;
datalines;
AGREE,   NEUTRAL
DISAGREE SOMEWHAT,  DISAGREE
AGREE SOMEWHAT,   AGREE
;
run;

data want;
   set have;
   array q   q10_1 -  q10_2 ;
   array rq rq10_1 - rq10_2 ;
   do i = 1 to dim(q);
      rq[i] = input(q[i],likert.);
   end;
   drop i;
run;

You could put as many variables on the Q array as there are coded alike just make sure there is a corresponding value in the R array.

 

Lining things up as I did in  the editor may help with that though I would would start with copy the like with the array q and then use the editor search and replace to find q and replace with rq.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 2449 views
  • 0 likes
  • 3 in conversation