求助:使用Proc Tabulate调整表格格式匹配目标输出
Proc Tabulate 表格格式调整方案
问题说明
需要将Proc Tabulate生成的表格调整为目标样式,当前输出与预期不符,已准备好图片资源但格式调整遇到阻碍。
当前代码
data cutepets; input gender $ type$ numpets; datalines; boy cockatiel 1 boy turtle 3 boy rabbit 4 girl cockatiel 2 girl turtle 3 girl rabbit 7 ; proc format; value $cutjpegs 'Cockatiel'='//vdi-fileshare01/UEMprofiles/029946759/Desktop/Cockatiel.jpg' ; value color 'type' = 'green'; run; proc tabulate data = cutepets; class type gender; classlev type / s=[background=$color. postimage=$cutjpegs. cellwidth=80]; var numpets ; table gender* numpets = ' ', type = ' ' sum = ' ' / rts=25 row=float box={label='# of pets'} ; run;
调整建议
修正格式定义错误:
color格式定义为数值型,但type是字符变量,需改为字符型格式,同时为非目标类型设置默认样式:proc format; value $cutjpegs 'Cockatiel'='//vdi-fileshare01/UEMprofiles/029946759/Desktop/Cockatiel.jpg' other='' /* 其他类型不显示图片 */ ; value $color /* 改为字符型格式 */ 'Cockatiel' = 'green' /* 针对特定类型设置背景色 */ other='white'; run;调整表格行列结构:目标样式应将宠物类型(
type)作为行维度,性别(gender)对应的宠物数量总和作为列维度,修改table语句:table type = ' ', gender*numpets*sum = ' ' / rts=25 row=float box={label='宠物类型'} /* 匹配目标行标签 */ ;优化样式应用对象:
classlev仅影响类级标签行,需将背景色和图片样式直接应用到type的行单元格:class type / s=[background=$color. postimage=$cutjpegs. cellwidth=80 textalign=center]; class gender;补充数值单元格对齐:为数值单元格添加居中样式,保证视觉一致性:
var numpets / s=[textalign=center];
完整调整后代码
data cutepets; input gender $ type$ numpets; datalines; boy cockatiel 1 boy turtle 3 boy rabbit 4 girl cockatiel 2 girl turtle 3 girl rabbit 7 ; proc format; value $cutjpegs 'Cockatiel'='//vdi-fileshare01/UEMprofiles/029946759/Desktop/Cockatiel.jpg' other='' ; value $color 'Cockatiel' = 'green' other='white'; run; proc tabulate data = cutepets; class type / s=[background=$color. postimage=$cutjpegs. cellwidth=80 textalign=center]; class gender; var numpets / s=[textalign=center]; table type = ' ', gender*numpets*sum = ' ' / rts=25 row=float box={label='宠物类型'} ; run;
内容的提问来源于stack exchange,提问作者Ryan Andrews
相关产品推荐
相关产品推荐

