1

I am thinking a question: How to create a new variable by using informat. like : we have a informat like that:

proc format ;
 invalue  $agegrpcd   
               1 = '<18'
               2 = '18 - 29'
               3 = '30 - 39'
               4 = '40 - 49'
               5 = '50 - 65'
               6 = '> 65'
               . = 'Missing' ;run;

and a dataset like that:

data age;
    input age 4. ;
    cards;
    22
    34
    13
    45
    64
    33
    ;run;

now I want to have a dataset like this:

age  agegroup
15  <18
25   18 - 29
33   30 - 39
45   40 - 49
64   50 - 65
77   > 65

Is there any way to put the numeric variable age into the character variable agegroup by using the informat I built? thanks.

DomPazz
  • 12,415
  • 17
  • 23
Wayne
  • 33
  • 1
  • 6

1 Answers1

4

you need to alter your PROC Format statement and create a format, not an informat.

proc format ;
value  agegrpcd   
           0-17 = '<18'
           18-29 = '18 - 29'
           30-39 = '30 - 39'
           40-49 = '40 - 49'
           50-65 = '50 - 65'
           66-high = '> 65'
           . = 'Missing' ;
run;

After that, use the PUT() function to convert the number to the character string.

data age;
set age;
agegroup=put( age, agegrpcd8.);
run;
DomPazz
  • 12,415
  • 17
  • 23
  • Agree. Key point is that OP needs to create a format, not an informat. – Quentin Jan 04 '16 at 14:42
  • @Quentin, thanks. I clarified to ensure that point was understood. – DomPazz Jan 04 '16 at 16:34
  • Thank you so mach OP. It is very helpful. But now I want to store the character ( <18, 18 - 29) in the new variable "agegroup" and not just mask it. – Wayne Jan 06 '16 at 04:37
  • You are not masking it. You are creating a character variable holding the format string. Run the code and look at the columns. – DomPazz Jan 07 '16 at 00:34