Search code examples
sassas-macro

Display a range if a value is in the range else if value is less or greater than range display '$'


I have numeric data i want to code a generic macro to display a range if the numeric variable value is falling in the range else if value is less or greater than range range then display '$$$'.


Solution

  • Format depends on whether age is a numeric or character variable. I have assumed numeric here, if it is character you need to add a $.

    proc format;
    value age_A
    0-14 = '$$$'
    15-25 = '15-25'
    25-high = '$$$'
    ;run;
    

    If you want to use this in a proc print/freq etc then use

    proc print data = ;
    var age;
    format age age_a.;
    run;
    

    if you want to change the data in a dataset then use the put function.

    data ;
    set;
    new_var = put(age, age_a.);
    run;