楼主: 美人百货
2521 7

[问答] proc report中关于compute的问题 [推广有奖]

  • 0关注
  • 0粉丝

等待验证会员

本科生

27%

还不是VIP/贵宾

-

威望
0
论坛币
123 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
280 点
帖子
14
精华
0
在线时间
157 小时
注册时间
2016-12-24
最后登录
2024-9-24

楼主
美人百货 发表于 2020-3-11 11:10:34 |AI写论文
20论坛币
求解释,为啥这段代码下,weight列并没有被染上色

proc report data = sashelp.class;
        column height weight;
        define height / display;
        define weight / display;
        compute height;
        if height > 60 then do;
                call define("weight","style","style = [color = red background = green]");
        end;
        endcomp;
run;


是因为选择列的时候,只能选择当前列或者更前面的列吗

关键词:proc report compute Report Comput repor

回帖推荐

Cecilia_Xi 发表于8楼  查看完整内容

[*]report item 的作用是与一个compute block联系起来:可以是 dataset variable, a computed variable, or a statistic [*]report item 在column statement中的位置十分重要:PROC REPORT是从左到右为报告行中的列分配值. 所以在你的code中,compute height时,因为weight在height的右边,其值全为missing 有两种解决方案:
已有 1 人评分经验 收起 理由
eijuhz + 20 精彩帖子

总评分: 经验 + 20   查看全部评分

沙发
Jia1Zhao 发表于 2020-3-11 17:02:07
你把compute height 改成compute weight,是可行的,你选取height列却变化weight不对

藤椅
美人百货 发表于 2020-3-12 08:53:20
Jia1Zhao 发表于 2020-3-11 17:02
你把compute height 改成compute weight,是可行的,你选取height列却变化weight不对
选取height列,可以对当前及前面的列进行变化的,后面的列为什么不能变化,附上code

proc report data = sashelp.class;
        column name height weight;
        define name / display;
        define height / display;
        define weight / display;
        compute height;
        if height > 60 then do;
                call define("name","style","style=[background=yellow]");/*这里name可以被染黄,但是换成weight就不行了*/
        end;
        endcomp;
run;

板凳
Jia1Zhao 发表于 2020-3-12 09:56:26
美人百货 发表于 2020-3-12 08:53
选取height列,可以对当前及前面的列进行变化的,后面的列为什么不能变化,附上code

proc report data ...
真的无解好像,只能对compute指定列及之前的

报纸
Jia1Zhao 发表于 2020-3-12 09:56:56
美人百货 发表于 2020-3-12 08:53
选取height列,可以对当前及前面的列进行变化的,后面的列为什么不能变化,附上code

proc report data ...
真的无解好像,只能对compute指定列及之前的

地板
美人百货 发表于 2020-3-13 08:39:02
Jia1Zhao 发表于 2020-3-12 09:56
真的无解好像,只能对compute指定列及之前的
只能这样解释了,感觉好奇怪

7
whymath 发表于 2020-3-15 09:24:01
确实如此,不过顺着这个思路想下去,应可以给出如下代码:
  1.         compute weight;
  2.         if height > 60 then do;
  3.                 call define("weight","style","style=[background=yellow]");/*这里name可以被染黄,但是换成weight就不行了*/
  4.         end;
  5.         endcomp;
复制代码

8
Cecilia_Xi 在职认证  发表于 2020-4-6 19:35:28
  • report item 的作用是与一个compute block联系起来:可以是 dataset variable, a computed variable, or a statistic
  • report item 在column statement中的位置十分重要:PROC REPORT是从左到右为报告行中的列分配值.

所以在你的code中,compute height时,因为weight在height的右边,其值全为missing
有两种解决方案:
  1. /*1. compute item 用column statement中的最后一个变量:weight*/

  2. proc report data = sashelp.class;
  3.         column height weight;
  4.         define height / display;
  5.         define weight / display;
  6.         compute weight;
  7.         if height > 60 then do;
  8.                 call define("weight","style","style = [color = red background = green]");
  9.         end;
  10.         endcomp;
  11. run;



  12. /*第二种,生成一个dummy report item 放在column statement的最后面,然后不print这个变量。

  13.   这种情况若调整report中要展示的变量时,如删除本来放在最后的变量weight,这时候不需要修改 compute report item:_lastvar*/

  14. proc report data = sashelp.class;
  15.         column height weight _lastvar;
  16.         define height / display;
  17.         define weight / display;
  18.                 define _lastvar/noprint;
  19.         compute _lastvar;
  20.         if height > 60 then do;
  21.                 call define("weight","style","style = [color = red background = green]");
  22.         end;
  23.         endcomp;
  24. run;
复制代码



已有 1 人评分经验 学术水平 热心指数 收起 理由
eijuhz + 40 + 2 + 1 精彩帖子

总评分: 经验 + 40  学术水平 + 2  热心指数 + 1   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-6 10:26