Sas 使用变量值作为格式名称

Sas 使用变量值作为格式名称,sas,Sas,我已经定义了fmtA和fmtB fmtA 1->1 2->2 口蹄疫 1->2 2->4 输入数据: x format y 1 fmtA 1 fmtB 2 fmtA 3 fmtA 我尝试根据列格式将列x格式化为y 有可能吗?是的,您可以使用putn功能执行此操作,例如: proc format; value fmtA 1 = 1 2 = 2 ; value fmtB 1 = 2 2 = 4 ; run; data have; input x format $; cards; 1 fmt

我已经定义了
fmtA
fmtB

fmtA

1->1

2->2

口蹄疫

1->2

2->4

输入数据:

x format y
1 fmtA   
1 fmtB
2 fmtA
3 fmtA
我尝试根据列
格式将列
x
格式化为
y


有可能吗?

是的,您可以使用
putn
功能执行此操作,例如:

proc format;
value fmtA
1 = 1
2 = 2
;
value fmtB
1 = 2
2 = 4
;
run;

data have;
input x format $;
cards;
1 fmtA   
1 fmtB
2 fmtA
3 fmtA
;
run;

data want;
set have;
y = putn(x,format);
run;

是的,您可以使用
putn
功能执行此操作,例如:

proc format;
value fmtA
1 = 1
2 = 2
;
value fmtB
1 = 2
2 = 4
;
run;

data have;
input x format $;
cards;
1 fmtA   
1 fmtB
2 fmtA
3 fmtA
;
run;

data want;
set have;
y = putn(x,format);
run;

PUTN和PUTC函数允许您在数据步骤运行时应用格式。尝试:

y=putn(x, cats(format,'.')) ;

PUTN和PUTC函数允许您在数据步骤运行时应用格式。尝试:

y=putn(x, cats(format,'.')) ;