Please help! The easiest way to recode multiple variables?

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Please help! The easiest way to recode multiple variables?

Say I have a dataset A with 200 variables having value from 1 to 5, measured by a 5-point likert scale. 50 of them have different directions from the others thereby are needed to be recoded to 1=5, 2=4, 3=3, 4=2, 5=1; what's the easiest way of doing this in SAS??? Thanks!


Accepted Solutions
Solution
‎11-25-2012 06:21 PM
New Contributor
Posts: 4

Re: Please help! The easiest way to recode multiple variables?

That was incredibly clever! Thank you so much!

View solution in original post


All Replies
Super Contributor
Posts: 644

Re: Please help! The easiest way to recode multiple variables?

Set up an array with the variables that need to be recoded:

Data want ;

     set have ;

          array newx{*} x3 x7 x9 x23 ... ;

          do k = 1 to dim(newk) ;

               newx{k} = 6 - newx{k} ;

          end ;

     drop k ;

Run ;

(not tested)

Richard in Oz

Solution
‎11-25-2012 06:21 PM
New Contributor
Posts: 4

Re: Please help! The easiest way to recode multiple variables?

That was incredibly clever! Thank you so much!

PROC Star
Posts: 7,363

Re: Please help! The easiest way to recode multiple variables?

You can also do the same thing creating and using an informat.  Depends upon your preference and how you like to document changes.  e.g.:

proc format;

  invalue reverse

  1=5

  2=4

  3=3

  4=2

  5=1

  ;

run;

data have;

  informat var2 var3 var6 reverse.;

  input var1-var7;

  cards;

1 2 3 4 5 3 2

2 3 4 5 1 2 3

;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 227 views
  • 6 likes
  • 3 in conversation