全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
580 10
2014-12-04
悬赏 100 个论坛币 已解决
a  b c d1 d2 e f1 f2 f3 f4 f5 g h   都是宏变量


总共有8类字母 a b c d e f g h
每类字母中又有该类的变量
现在要求,在8类字母中取其中的6类,而对于那些一类字母中多于1个变量的字母,则在这类字母中取其中的一个

如何列举出所有的情况


keep  每种情况产生的组合

最佳答案

jl60156 查看完整内容

%macro test; %let x1=a1 a2; %let x2=b; %let x3=c; %let x4=d; %let x5=e; %let x6=f1 f2 f3; %let x7=g; %let x8=h; %let k=6; %let ncomb=%sysfunc(comb(8,&k)); %do i=1 %to &ncomb+1; %syscall allcomb(i, k, x1, x2, x3, x4, x5, x6, x7, x8); %do j=1 %to 6; %let n&j=%sysfunc(countw(&&x&j)); %end; %do m1=1 %to &n1; %let y1=%scan(&x1,&m1) ...
二维码

扫码加我 拉你入群

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

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

全部回复
2014-12-4 15:02:03
%macro test;
   %let x1=a1 a2;
   %let x2=b;
   %let x3=c;
   %let x4=d;
   %let x5=e;
   %let x6=f1 f2 f3;
   %let x7=g;
   %let x8=h;
   %let k=6;
   %let ncomb=%sysfunc(comb(8,&k));
   %do i=1 %to &ncomb+1;
      %syscall allcomb(i, k, x1, x2, x3, x4, x5, x6, x7, x8);
                  %do j=1 %to 6;
                %let n&j=%sysfunc(countw(&&x&j));
                  %end;
                 %do m1=1 %to &n1;
                        %let y1=%scan(&x1,&m1);
                        %do m2=1 %to &n2;
                                %let y2=%scan(&x2,&m2);
                                %do m3=1 %to &n3;
                                        %let y3=%scan(&x3,&m3);
                                        %do m4=1 %to &n4;
                                                %let y4=%scan(&x4,&m4);
                                                %do m5=1 %to &n5;
                                                        %let y5=%scan(&x5,&m5);
                                                        %do m6=1 %to &n6;
                                                                %let y6=%scan(&x6,&m6);
                                                               
data data&i.x1&m1.x2&m2.x3&m3.x4&m4.x5&m5.x6&m6        (keep=&y1 &y2 &y3 &y4 &y5 &y6);
        set yourdata;
run;       

                                                                %let ncomind&i.x1&m1.x2&m2.x3&m3.x4&m4.x5&m5.x6&m6=&y1 &y2 &y3 &y4 &y5 &y6;
                                                                %put ncomind&i.x1&m1.x2&m2.x3&m3.x4&m4.x5&m5.x6&m6=&&ncomind&i.x1&m1.x2&m2.x3&m3.x4&m4.x5&m5.x6&m6;
                                                        %end;
                                                %end;
                                        %end;
                                %end;
                        %end;
                %end;
   %end;

%mend;
     
%test;
二维码

扫码加我 拉你入群

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

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

2014-12-4 15:57:41
data test_a  test_b test_c test_d1 test_d2 test_e test_f1 test_f2 test_f3 test_f4 test_f5 test_g;
input a @@;
datalines;
0
1
;
run;

proc sql  noprint;
create table test
as  
select test_a.a as a,  test_b.a as b,  test_c.a as c ,test_d1.a as d1, test_d2.a as d2 ,test_e.a as e ,test_f1.a as f1 ,test_f2.a as f2, test_f3.a as f3 ,test_f4.a as f4 ,test_f5.a as f5, test_g.a as g
from test_a , test_b ,test_c ,test_d1, test_d2 ,test_e ,test_f1 ,test_f2, test_f3 ,test_f4 ,test_f5, test_g ;
quit;

data test1;
set test;
n=a +b +c+ d1+ d2+ e +f1+ f2+ f3+ f4+ f5+ g;
if n=6 and d1+ d2<=1 and f1+ f2+ f3+ f4+ f5<=1;
run;

proc print;
run;
二维码

扫码加我 拉你入群

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

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

2014-12-4 20:26:41
yanjiyunning 发表于 2014-12-4 15:57
data test_a  test_b test_c test_d1 test_d2 test_e test_f1 test_f2 test_f3 test_f4 test_f5 test_g;
...
没看懂啊   ,是不是我的意思表达错了
二维码

扫码加我 拉你入群

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

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

2014-12-4 20:28:03
yanjiyunning 发表于 2014-12-4 15:57
data test_a  test_b test_c test_d1 test_d2 test_e test_f1 test_f2 test_f3 test_f4 test_f5 test_g;
...
a b 等这些事宏变量吗      不是先用let 去定义吗
二维码

扫码加我 拉你入群

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

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

2014-12-4 23:15:42
jl60156 发表于 2014-12-4 23:08
%macro test;
   %let x1=a1 a2;
   %let x2=b;
多谢高手
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群