-1

I have a series of string variables (x, y, z) whose observations I need to change from strings (x= less than 1 mile, more than 1 mile less then 5 miles, etc.) to integers (xrecode= 1, 2, etc).

Is there any automated way to do this? I need an automated method that gets away from this values equal 1, that value equals 2, ...(Do Loops, Arrays, Macros welcome)?

Englishman Bob
  • 377
  • 2
  • 13
  • 1
    Formats and/or a lookup table. Most likely a format. If you want more beyond that post more details, including a sample of what you have, what you expect and most importantly, what you've currently tried. – Reeza Oct 31 '17 at 00:23
  • I need help figuring out building co Hde to select multiple variables with missing values. Beginning code: PROC SQL; SELECT x INTO :x SEPERATED BY " " FROM have; QUIT; %let x = &x; – Englishman Bob Oct 31 '17 at 14:13
  • Post what you've tried by editing the questions, not by including code in the comments. That's not legible. – Reeza Oct 31 '17 at 15:28

2 Answers2

1

You can use an INFORMAT to convert from text to integer.

proc format ;
  invalue distance 
   'less than 1 mile'=1
   'more than 1 mile'=2
   'less then 5 miles'=3
  ;
quit;

You can apply the same operation to multiple similar columns by looping over an ARRAY.

data want ;
  set have ;
  array in x y z ;
  array out nx ny nz ;
  do i=1 to dim(in);
    out(i)=input(in(i),distance.);
  end;
run;
Tom
  • 47,574
  • 2
  • 16
  • 29
0

Reeza is right. Proc format for instance:

proc format; 
    value ToForm 
    low-1 = 'less than one'
    1-5 = 'one to five'
    5-high = 'over five'
;quit;

data wanted;
    set begin;
    format val_to_format ToForm.;
run;

For more on proc format see: SAS documentation: proc format

pinegulf
  • 1,334
  • 13
  • 32