全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3810 6
2016-03-03
有如下数据集:
复制代码
最后生成一个num变量,是x1~x6这6个变量中取不同值的个数,比如第一条记录的6个变量值去重后是c1,c2,c3,c5,因此num=4;

谢谢高手指点!
二维码

扫码加我 拉你入群

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

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

全部回复
2016-3-3 03:15:50
data test;
  input x1 $ x2 $ x3 $ x4 $ x5 $ x6 $ ;
  cards;
c1 c3 c5 c3 c1 c2
c2 c8 c9 c2 c9 c8
;
run;

data test ;
  set test end=eof ;
  if eof then call symput("TotalRecords", _n_) ;
run;
%put &totalRecords ;

proc transpose data = test out=one ;
  var x1 - x6 ;
run;

%macro getcount ;
proc sql ;
  create table two as
  select %do i=1 %to &totalRecords ;
           col&i,
         %end ;
         _NAME_
  from one
  union
  select %do i=1 %to &totalRecords ;
           strip(put(count(distinct col&i.), best8.)) as col&i ,
                 %end ;
                 'Num' as _NAME_
  from one ;
quit ;
%mend getcount ;

%getcount

proc transpose data=two out=temp(drop=_name_) ;
  id _NAME_ ;
  var COL: ;
run;

data temp (drop=num);
  set temp ;
  num_count=input(num,best8.) ;
run;




二维码

扫码加我 拉你入群

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

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

2016-3-3 13:24:45
yingzi2003 发表于 2016-3-3 03:15
data test;
  input x1 $ x2 $ x3 $ x4 $ x5 $ x6 $ ;
  cards;
思路不错,必须赞一个~~
二维码

扫码加我 拉你入群

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

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

2016-3-3 18:03:52
data test;
  input x1 $3. x2 $3. x3  $3. x4  $3. x5 $3.  x6 $3.;
  cards;
c1 c3 c5 c3 c1 c2
c2 c8 c9 c2 c9 c8
;
run;



data test_one;
        set test;
        array x(6) x1-x6;
        array a(6) $ a1-a6;
        a1=x1;
        count=0;
        num_count=0;
        do i=2 to 6;
                do j=1 to i-1;
                if x(i) eq a(j) then count=1;
                end;
                if count eq 0 then a(j)=x(i);
                count=0;
        end;

        do j=1 to 6;
                if a(j) ne '' then num_count+1;
        end;

        drop a1-a6 count i j;
run;
二维码

扫码加我 拉你入群

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

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

2016-3-3 20:32:29
复制代码
二维码

扫码加我 拉你入群

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

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

2016-3-4 08:54:18
复制代码
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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