全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
4196 10
2013-09-21
假设宏变量  %let str=v1 v2 v3;       /*v的个数可能超过3,v1 v2 v3 v4.....vn*/
我要生成几个新的宏变量,每一个新宏变量的值是 v1 v2 v3组合的一种情况,如:
str1=v1
str2=v2
str3=v3
str4=v1 v2
str5=v1 v3
str6=v2 v3

请教下,哪位能有好的,快捷实现的方法,谢谢!!

二维码

扫码加我 拉你入群

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

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

全部回复
2013-9-22 22:49:00
let me try:

data test;
  input serial var $;
  datalines;
  1 v1
  2 v2
  3 v3
  ;
  run;

proc sql;
    create table tmp as(
    select var as newvar from test union all
    select cat(a.var,b.var) as newvar from test a,test b where  a.serial<b.serial union all
    select cat(a.var,b.var,c.var) as newvar from test a,test b,test c where  a.serial<b.serial and b.serial<c.serial);
quit;

data fstr;
     set tmp;
     serial +1;
run;

proc sql;
   select newvar into :str1 from fstr where serial=1;
   select newvar into :str2 from fstr where serial=2;
   select newvar into :str3 from fstr where serial=3;
   select newvar into :str4 from fstr where serial=4;
   select newvar into :str5 from fstr where serial=5;
   select newvar into :str6 from fstr where serial=6;
quit;

%put &str1;
%put &str2;
%put &str3;
%put &str4;
%put &str5;
%put &str6;
二维码

扫码加我 拉你入群

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

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

2013-9-23 00:41:47
1. Functions allcomb, allperm
http://support.sas.com/documenta ... .htm#a003112302.htm
2. PROC PLAN
二维码

扫码加我 拉你入群

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

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

2013-9-23 12:19:33
PhoenixHuang 发表于 2013-9-22 22:49
let me try:

data test;
嗯,我后来用allcomb, 好像实现起来还比较快捷,你的方法也不错:

data _null_;
   array x[5] $3 ('ant' 'bee' 'cat' 'dog' 'ewe');
   n=dim(x);
   k=3;
   ncomb=comb(n,k);
   do j=1 to ncomb+1;
      call allcomb(j, k, of x
  • );
          put j 5. +3 x1-x3;
       end;
    run;
    SAS writes the following output to the log:
        1   ant bee cat
        2   ant bee ewe
        3   ant bee dog
        4   ant cat dog
        5   ant cat ewe
        6   ant dog ewe
        7   bee dog ewe
        8   bee dog cat
        9   bee ewe cat
       10   dog ewe cat
       11   dog ewe cat
  • 二维码

    扫码加我 拉你入群

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

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

    2013-9-23 12:20:31
    邓贵大 发表于 2013-9-23 00:41
    1. Functions allcomb, allperm
    http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default ...
    嗯,谢谢,我后来自己找到了这种方法,挺不错的
    二维码

    扫码加我 拉你入群

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

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

    2013-9-24 05:14:35
    使用allcomb()方程是非常美妙的程序.在以前我也有此需要,但是没有静下来考虑是否可以用宏来编写.今天决心试一试.

    我的程序此处可见
    但是,在运行超过计13个字符串的时候,有BUG.也许大家有什么意见.
    京剧

    二维码

    扫码加我 拉你入群

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

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

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

    说点什么

    分享

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