How can I make a character variable equal to the formatted value of a numeric variable for arbitrary SAS formats?

前端 未结 5 573
不知归路
不知归路 2021-02-08 19:57

If I have a numeric variable with a format, is there a way to get the formatted value as a character variable?

e.g. I would like to write something like the following to

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-08 20:39

    The VVALUE function formats the variable passed to it using the format associated with the variable. Here's the code using VVALUE:

    data test;
      format i ddmmyy10.;
      i = "10JUN2009"d;
    run;
    
    data _null_;
      set test;
      i_formatted = vvalue(i);
      put i_formatted;
    run;
    

    While cmjohns solution is slightly faster than this code, this code is simpler because there are no macros involved.

提交回复
热议问题