0

我想获取变量级别的数量以及唯一标识符输出的变量,但目前我的方法不起作用。然后我想使用唯一 ID 并关联来自 proc freq 的数字 1-num_levels。

这是我对proc freq的内容:

PROC FREQ DATA=my_data (keep=IDs) nlevels;
table all/out=out_data;
%let dim=levels;
%let IDs;
run;

然后我尝试使用宏变量,但它没有用,所以我包含了我的 proc 格式的手动版本,以便更好地了解我想要实现的目标,但希望能够让它更加自动化。

PROC FORMAT; 
INVALUE INDEX
"1234" = 1
"2345" = 2
.
.
.
"8901" =25;
/*25 represents the output of the levels 
variable from proc freq but I couldn't figure out how to grab that either*/
RUN;

任何帮助,将不胜感激。谢谢!

4

1 回答 1

2

这是一个完全有效的解决方案,它说明了 PROC FORMAT CNTLIN 的执行方式。这里的想法是用观察编号来掩盖名称。

*Create list of unique names;
proc freq data=sashelp.class noprint;
    table name/out = mask;
run;

*create control data set. Variables that need to be set are:
   fmtname, start, label and type;

data name_fmt;
    set mask;
    fmtname = 'namefmt';
    type='J';

    *J specified character informat, C would be character format;
    start=name;
    label = put(_n_, z2.); *Use the row number as the recoded value;
run;

*create the format;
proc format cntlin=name_fmt;
run;

*Sample usage;
data class;
    set sashelp.class;
    name_masked = input(name, $namefmt.);
    drop name;
run;
于 2017-04-05T23:19:01.180 回答