楼主: jackbt123
2729 8

[原创博文] [SAS Data Management] File Drawer Problem (抽屉问题) [推广有奖]

  • 0关注
  • 0粉丝

硕士生

59%

还不是VIP/贵宾

-

威望
0
论坛币
110 个
通用积分
0.3000
学术水平
2 点
热心指数
4 点
信用等级
2 点
经验
847 点
帖子
56
精华
0
在线时间
263 小时
注册时间
2008-11-28
最后登录
2017-9-21

楼主
jackbt123 发表于 2010-3-8 00:45:45 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
假设有4个不同的位置(P1,P2,P3, P4),每个位置都可以放红,黄, 绿 3 种颜色的球。
这样总共可以有 3 X 3 X 3 X 3 = 81 种不同的放法。

现在我想和各位SAS专版的会员讨论一下如何把这81种不同的放法都列出来。

我的方法如下:
第一步:建一个数列 (1,2,3,4,5,6,7,8,9,10,11,12)
第二步:用 MACRO  %permute(4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) ,将从12个不同的数里任意选4个数的所有不同排列都列出来。
             (There are 4 variables: r1, r2, r3, r4 in SAS dataset output)
http://support.sas.com/techsup/technote/ts498.html
第三步 :在所有的排列中,将(1, 2, 3, 4)       替换成 ("R")
                                              将(5, 6, 7, 8)       替换成 ("Y")
                                              将(9, 10, 11, 12) 替换成 ("G")
第四步:合并 r1, r2, r3, r4 (TRIM(r1) || TRIM(r2) || TRIM(r3) || TRIM(r4))成为一个新的variable: RYG.
第五步:删除所有重复的情况(select distinct RYG),最后得到81种不同的放法。

请各位SAS专版的会员分享一下你们的方法。谢谢!



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Management Managemen problem Manage Drawer 会员 如何

回帖推荐

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

bobguy, thank you once again. I learn so much useful sas programming logic and idea from you (or your coding). Here is Macro for Combination to generate all cases by choosing R out of any list with length >= R. Reference: http://support.sas.com/techsup/technote/ts498.html %MACRO COMBINATION(R) / PARMBUFF; /* the PARMBUFFf option assigns the invocation parameter list to the macro variable &SY ...

bobguy 发表于2楼  查看完整内容

Here is a simple one. data needed; array p[4] $1 p1-p4; array b[3] $1 ('R','Y','G'); length comb $4; do i1 = 1 to 3; do i2 = 1 to 3; do i3 = 1 to 3; do i4 = 1 to 3; comb=catt( b(i1), b(i2), b(i3), b(i4) ); output; end; end; end; end; keep comb; run; proc print; ru ...

本帖被以下文库推荐

沙发
bobguy 发表于 2010-3-8 02:07:48
jackbt123 发表于 2010-3-8 00:45
假设有4个不同的位置(P1,P2,P3, P4),每个位置都可以放红,黄, 绿 3 种颜色的球。
这样总共可以有 3 X 3 X 3 X 3 = 81 种不同的放法。

现在我想和各位SAS专版的会员讨论一下如何把这81种不同的放法都列出来。

我的方法如下:
第一步:建一个数列 (1,2,3,4,5,6,7,8,9,10,11,12)
第二步:用 MACRO  %permute(4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) ,将从12个不同的数里任意选4个数的所有不同排列都列出来。
             (There are 4 variables: r1, r2, r3, r4 in SAS dataset output)
http://support.sas.com/techsup/technote/ts498.html
第三步 :在所有的排列中,将(1, 2, 3, 4)       替换成 ("R")
                                              将(5, 6, 7, 8)       替换成 ("Y")
                                              将(9, 10, 11, 12) 替换成 ("G")
第四步:合并 r1, r2, r3, r4 (TRIM(r1) || TRIM(r2) || TRIM(r3) || TRIM(r4))成为一个新的variable: RYG.
第五步:删除所有重复的情况(select distinct RYG),最后得到81种不同的放法。

请各位SAS专版的会员分享一下你们的方法。谢谢!
Here is a simple one.

data needed;
   array p[4]  $1 p1-p4;
   array b[3]  $1 ('R','Y','G');
   length  comb $4;
   do i1 = 1 to 3;
      do i2 = 1 to 3;
         do i3 = 1 to 3;
             do i4 = 1 to 3;
               comb=catt( b(i1), b(i2), b(i3), b(i4) );
               output;
             end;
         end;
      end;
    end;
   keep  comb;
run;

proc print; run;


已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

藤椅
jackbt123 发表于 2010-3-8 02:57:46
hi bobguy,  thank you so much.
could you share your sas programming for combinations and permutations?
best,

板凳
jackbt123 发表于 2010-3-8 05:40:19
假设有R个位置

%MACRO GYR(R);

DATA GYR;
KEEP V1 - V&R;
ARRAY ColorList{3} $ 1 ("G", "Y", "R");

%DO S = 1 %TO &R;                 
DO i&S = 1 TO DIM(ColorList);
%END;
%DO S = 1 %TO &R;                 
V&S = ColorList{i&S};
%END;
OUTPUT;
%DO S = 1 %TO &R;                 
END;
%END;
RUN;

%MEND GYR;

报纸
bobguy 发表于 2010-3-8 08:40:08
jackbt123 发表于 2010-3-8 05:40
假设有R个位置

%MACRO GYR(R);

DATA GYR;
KEEP V1 - V&R;
ARRAY ColorList{3} $ 1 ("G", "Y", "R");

%DO S = 1 %TO &R;                 
DO i&S = 1 TO DIM(ColorList);
%END;
%DO S = 1 %TO &R;                 
V&S = ColorList{i&S};
%END;
OUTPUT;
%DO S = 1 %TO &R;                 
END;
%END;
RUN;

%MEND GYR;
Your macro is good one. But I am not sure what is your question in the other message.

地板
jackbt123 发表于 2010-3-8 09:39:18
M 个数里任意选 N 个数的所有排列(permutations).
假如你有时间的话,请你分享一下你的SAS codes.
谢谢。

7
bobguy 发表于 2010-3-8 12:16:25
jackbt123 发表于 2010-3-8 09:39
M 个数里任意选 N 个数的所有排列(permutations).
假如你有时间的话,请你分享一下你的SAS codes.
谢谢。
Here is a case for 3 out 7 permutations. It should be easily generalize in a macro for a general case.



data tmp;
   array y(7) $1 _temporary_ ( "1","2","3","4","5","6","7") ;

   do c1 = 1 to 7;
      do c2 = 1 to 7;
         if c1 = c2 then continue ;
         do c3 = 1 to 7;
            if c1 = c3 or c2 = c3 then continue ;
                  x1=y(c1); x2=y(c2); x3=y(c3);        
                  output ;
               end ;
            end ;
         end ;
     
run ;

proc print; run;

8
jackbt123 发表于 2010-3-9 10:55:24
bobguy, thank you once again.
I learn so much useful sas programming logic and idea from you (or your coding).
Here is Macro for Combination to generate all cases by choosing R out of any list with length >= R.
Reference: http://support.sas.com/techsup/technote/ts498.html

%MACRO COMBINATION(R) / PARMBUFF; /* the PARMBUFFf option assigns the invocation parameter list to the macro variable &SYSPBUFF */

%LET M = 2;
%LET LIST = ;
%DO %WHILE (%QSCAN(&SYSPBUFF, &M, %STR(,%))) NE );
   %LET ELEMENT = "%QSCAN(&SYSPBUFF, &M, %STR(,%)))";
   %IF &M = 2 %THEN %LET LIST = &ELEMENT;
   %ELSE %LET LIST = &LIST, &ELEMENT;
   %LET M = %EVAL(&M + 1);
%END;
%LET K = %EVAL(&M - 2);

%PUT &LIST;
%PUT &R;
%PUT &K;

DATA COMBINATION;
KEEP V1 - V&R;
ARRAY L{&K} $ 1 (&LIST);
DO i1 = 1 TO DIM(L);
%DO S = 2 %TO &R;
   DO i&S = i%EVAL(&S - 1) + 1 TO DIM(L);
%END;
   %DO S = 1 %TO &R;                 
      V&S = L{i&S};
   %END;
   OUTPUT;
%DO S = 1 %TO &R;                 
   END;
%END;
RUN;

%MEND COMBINATION;

Testing
%COMBINATION(4,A,B,C,D,E,F);
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

9
bobguy 发表于 2010-3-9 11:38:35
8# jackbt123

That is great! Thanks.

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 10:56