BookmarkSubscribeRSS Feed

It would be nice to have a CAT_() type function that uses the format applied to the variables rather than Best for numeric variables. 

 

For example, I would have preferred if the WANT_STRING was the same as the output from the HAVE_STRING code, since a format is applied to the variables already. 

 

data have;

    format date1-date20 date9.;
    format datec1-datec20 $9.;
    length datec1-datec20 $9. x_string y_string $256.;
    array _date(*) date1-date20;
    array _datec(*) $  datec1-datec20;

    do i=1 to dim(_date);
        _date(I)=floor(ranuni(25)*365+1);
        _datec(I)=trim(put(_date(I), date9.));
    end;
    
    
    have_string=catx(", ", of _date(*));
    want_string=catx(", ", of _datec(*));
run;

proc print ;
run;
4 Comments
PGStats
Opal | Level 21

Yes! Call them CATXF, CATSF, CATQF, CATTF. "F" for formatted.

ballardw
Super User

Of course as soon as you have one of these functions you find out that you don't want your current default format but actually want to use another one but NOT change the default for the variable(s) [which would be easy]...

PhilC
Rhodochrosite | Level 12

This would be nice.  This code does what we want-- hopefully the reader cringes at it and votes this up.

 

data have;

    format date1-date20 date9.;
    format datec1-datec20 $10.;
    length datec1-datec20 $10. x_string y_string $256.;
    length want_string $200;
    array _date(*) date1-date20;
    array _datec(*) $  datec1-datec20;

    do i=1 to dim(_date);
        _date(I)=floor(ranuni(25)*365+1);
    end;
    
    
    have_string=catx(", ", of _date(*));

    do i=1 to dim(_date);
        _datec(I)=trim(put(_date(I), date9.))||',';
    end;

    dc_addr=addr(datec1);
    want_string=peekC(dc_addr,199);
run;

Reeza
Super User

@PhilC That's one way to get change 😉