Dynamic variable names in SAS

前端 未结 4 1126
星月不相逢
星月不相逢 2021-01-20 02:16

Is there a way in SAS to specify dynamic variable names in code? i.e. use different variables on different observations based on the value of another variable?

For

4条回答
  •  长情又很酷
    2021-01-20 02:41

    data want;
        set have;
        length _var_name $32 _var_num 5;
        array vars(*) var: ;
        /* if you want name of variable */
        _var_name=VNAME(vars(index));
        /* if you want numeric suffix of variable 
                and suffix is not same as position of variable in array
              (so that vars(index) is not usable */
        _var_num=INPUT(SUBSTR(_var_name, ANYDIGIT(_var_name)),32.);
    run;
    

    So what you need is VNAME() function.

提交回复
热议问题