楼主: lnlhckao123
1372 8

[问答] 200论坛币请问怎样生成一个变量含有不同记录 [推广有奖]

  • 0关注
  • 3粉丝

副教授

62%

还不是VIP/贵宾

-

威望
0
论坛币
14810 个
通用积分
10.6125
学术水平
7 点
热心指数
4 点
信用等级
4 点
经验
12566 点
帖子
754
精华
0
在线时间
405 小时
注册时间
2010-8-21
最后登录
2025-6-7

楼主
lnlhckao123 发表于 2013-5-17 03:01:54 |AI写论文
200论坛币
请问怎样生成一个变量含有不同记录:如在数据集中生成a变量,a变量含有两组,一组包含7个记录,另一组包含5个记录,结果如下:谢谢高手指点!!
a
1
1
1
1
1
1
1
2
2
2
2
2


最佳答案

yongyitian 查看完整内容

/* is this what you want? */ data test; input group total yes no; datalines; 1 116 85 31 2 120 107 13 ; run; data long; set test; do i = 1 to yes; heal = 1; noheal = 0; result ='heal '; output; end; do i = 1 to no; heal = 0; noheal = 1; result = 'no_heal'; output; end; drop total i yes no; run; proc print dat ...
关键词:200论坛币 0论坛币 论坛币 高手指点 数据集 记录
即使在人大经济论坛这个网络世界,我仍以真诚为基础与我的好友进行交往!

沙发
yongyitian 发表于 2013-5-17 03:01:55
/* is this what you want? */

data test;
input group total yes no;
datalines;
1 116 85 31
2 120 107 13
; run;

data long;
    set test;
  do i = 1 to yes;
    heal = 1;
    noheal = 0;
    result ='heal    ';
    output;
end;
   do i = 1 to no;
       heal = 0;
      noheal = 1;
      result = 'no_heal';
      output;
   end;
   drop total i yes no;
run;

proc print data=long; run;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
lnlhckao123 + 3 + 3 + 3 热心帮助其他会员

总评分: 学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

藤椅
boe 发表于 2013-5-17 03:34:18
方法有很多,不知道你进一步的需求是什么,还请把你的一小部分原始数据和你明确的需求说出来
Gorgeous girl , I love !

板凳
lnlhckao123 发表于 2013-5-17 03:58:11
谢谢boe!我再想请教一下高手,我想生成如下结果,应该怎样编sas程序,结果如下:谢谢!!

组别          例数          愈合        未愈合      愈合率         
常规          116             85         31           73.28%
新药组       120            107       13           89.17%

合计          236            192        44           81.36%
即使在人大经济论坛这个网络世界,我仍以真诚为基础与我的好友进行交往!

报纸
boe 发表于 2013-5-17 04:19:24
Gorgeous girl , I love !

地板
yuerqieqie 发表于 2013-5-17 04:27:33
lnlhckao123 发表于 2013-5-17 03:58
谢谢boe!我再想请教一下高手,我想生成如下结果,应该怎样编sas程序,结果如下:谢谢!!

组别          ...
proc summary data = input;
    class 组别;
    var 愈合;
    output out = step1 sum = ;
run;
data result;
    set step1;
    if _type_ = 0 then 组别 = '合计';
    未愈合 = _freq_ - 愈合;
    愈合率 = 愈合 / _freq_;
    rename _freq_ = 例数;
run;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
lnlhckao123 + 2 + 2 + 2 热心帮助其他会员

总评分: 学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

7
boe 发表于 2013-5-17 04:48:25
lnlhckao123 发表于 2013-5-17 03:58
谢谢boe!我再想请教一下高手,我想生成如下结果,应该怎样编sas程序,结果如下:谢谢!!

组别          ...
以后就这样提问吧。
Gorgeous girl , I love !

8
lnlhckao123 发表于 2013-5-19 00:09:32
谢谢yongyitian!您理解我帖子的目的非常准确!还用,我想再问您一下,也是我目的的最后的一个步骤,我的程序如下:我想在data=long的基础上在生成一个变量no,使每一个no均等于1.如下所示(当然,no值我是手工做出来),谢谢!!
data test;
input group  b   c;
cards;
  1   12   13
  2   14   15
  ;
  run;

  data long;
   set test2;
   do i=1 to b;
      result=1;
        output;
        end;
  do i=1 to c;
      result=0;
        output;
    end;
  drop b c i;
run;




                                                 Obs   group  result   no

                                                    1      1         1        1
                                                    2      1         1        1
                                                    3      1         1        1
                                                    4      1         1        1
                                                    5      1         1        1
                                                    6      1         1        1
                                                    7      1         1        1
                                                    8      1         1        1
                                                    9      1         1        1
                                                   10      1         1        1
                                                   11      1         1        1
                                                   12      1         1        1
                                                   13      1         0        1
                                                   14      1         0        1
                                                   15      1         0        1
                                                   16      1         0        1
                                                   17      1         0        1
                                                   18      1         0        1
                                                   19      1         0        1
                                                   20      1         0        1
                                                   21      1         0        1
                                                   22      1         0        1
                                                   23      1         0        1
                                                   24      1         0        1
                                                   25      1         0        1
                                                   26      2         1        1
                                                   27      2         1        1
                                                   28      2         1        1
                                                   29      2         1        1
                                                   30      2         1        1
                                                   31      2         1        1
                                                   32      2         1        1
                                                   33      2         1        1
                                                   34      2         1        1
                                                   35      2         1        1
                                                   36      2         1        1
                                                   37      2         1        1
                                                   38      2         1        1
                                                   39      2         1        1
                                                   40      2         0        1
                                                   41      2         0        1
                                                   42      2         0        1
                                                   43      2         0        1         
                                                   44      2         0        1
                                                   45      2         0        1
                                                   46      2         0        1
                                                   47      2         0        1
                                                   48      2         0        1
                                                   49      2         0        1
                                                   50      2         0        1
                                                   51      2         0        1
                                                   52      2         0        1
                                                   53      2         0        1
                                                   54      2         0        1
如果我用如下程序,则会出现如下结果,出现不了我手工的结果,为什么?谢谢!!
data test;
input group  b   c;
cards;
  1   12   13
  2   14   15
  ;
  run;

  data long;
   set test2;
   do i=1 to b;
      result=1;
        output;
        end;
  do i=1 to c;
      result=0;
        output;
    end;
  drop b c i;

  if result<2 then no=1;
run;

                                              Obs  group  result  no

                                                 1      1         1       .
                                                 2      1         1       .
                                                 3      1         1       .
                                                 4      1         1       .
                                                 5      1         1       .
                                                 6      1         1       .
                                                 7      1         1       .
                                                 8      1         1       .
                                                 9      1         1       .
                                                10      1         1       .
                                                11      1         1       .
                                                12      1         1       .
                                                13      1         0       .
                                                14      1         0       .
                                                15      1         0       .
                                                16      1         0       .
                                                17      1         0       .
                                                18      1         0       .
                                                19      1         0       .
                                                20      1         0       .
                                                21      1         0       .
                                                22      1         0       .
                                                23      1         0       .
                                                24      1         0       .
                                                25      1         0       .
                                                26      2         1       .
                                                27      2         1       .
                                                28      2         1       .
                                                29      2         1       .
                                                30      2         1       .
                                                31      2         1       .
                                                32      2         1       .
                                                33      2         1       .
                                                34      2         1       .
                                                35      2         1       .
                                                36      2         1       .
                                                37      2         1       .
                                                38      2         1       .
                                                39      2         1       .
                                                40      2         0       .
                                                41      2         0       .
                                                42      2         0       .
                                                43      2         0       .
                                                44      2         0       .
                                                45      2         0       .
                                                46      2         0       .
                                                47      2         0       .
                                                48      2         0       .
                                                49      2         0       .
                                                50      2         0       .
                                                51      2         0       .
                                                52      2         0       .
                                                53      2         0       .
                                                54      2         0       .



















即使在人大经济论坛这个网络世界,我仍以真诚为基础与我的好友进行交往!

9
yongyitian 发表于 2013-5-19 02:25:32
/* Like this */
data long;
   set test2;
   do i=1 to b;
      result=1;
      no=1;
        output;
        end;
  do i=1 to c;
      result=0;
      no=1;
        output;
    end;
  drop b c i;
run;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
lnlhckao123 + 3 + 3 + 3 精彩帖子

总评分: 学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

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

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