全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1048 1
2019-06-25
/* macro extunique */
%macro extunique(Dsin,idvar,dsout,dspup);
/* extract the id's only to speed calculations*/
data temp_allids;
set &dsin;
keep &idvar;
run;
/*extract the id's with count>1*/
data temp_nid;
set temp_uid;
if _count>1 then output;
keep &idvar;
run;
/*sort the data using idvar and output only one row per
idvar value*/
proc sort data=&sin;
by &idvar;
run;
data &dsout;
set &dsin;
by &idvar;
if fitst.&idvar;
run;

/*extract the full records for the repeates id's*/
proc sql noprint;
create table &dsdup as select b.*from temp_nid a,&dsin b
where a.&idvar=b.&idvar;
run;
quit;
/*clean the workspace*/
proc datasets nodetails nolist;
delete temp_allids temp_uid temp_nid;
run;
quit;
%mend;

data mv;
input id balance @@;
datalines;
01 1223 01 2322 02 344 02 21221  
03 2334 04 222 05 222 06 222
;
run;

%let idvar=id;
%let dsin=mv;
%let dsout=mv_id;
%let dsdup=duplicate_id;
%extunique(&dsin,&idvar,&dsout,&dsdup);

set temp_uid; 书中后面给了个宏,但是这个表是从哪来的???执行也是错误
ERROR: 文件“WORK.TEMP_UID.DATA”不存在。



二维码

扫码加我 拉你入群

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

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

全部回复
2019-6-25 14:34:25
/* macro extunique */
%macro extunique(Dsin,idvar,dsout,dspup);
/* extract the id's only to speed calculations*/
data temp_allids;
set &dsin;
keep &idvar;
run;
/*extract the unique id's and their conts*/
proc sql noprint;
create table temp_uid as select &idvar,count(&idvar) as _count
from temp_allids group by &idvar;
run;quit;
/*extract the id's with count>1*/
data temp_nid;
set temp_uid;
if _count>1 then output;
keep &idvar;
run;
/*sort the data using idvar and output only one row per
idvar value*/
proc sort data=&dsin;
by &idvar;
run;
data &dsout;
set &dsin;
by &idvar;
if first.&idvar;
run;

/*extract the full records for the repeates id's*/
proc sql noprint;
create table &dsdup as select b.*from temp_nid a,&dsin b
where a.&idvar=b.&idvar;
run;
quit;
/*clean the workspace*/
proc datasets nodetails nolist;
delete temp_allids temp_uid temp_nid;
run;
quit;
%mend;

data mv;
input id balance @@;
datalines;
01 1223 01 2322 02 344 02 21221  
03 2334 04 222 05 222 06 222
;
run;

%let idvar=id;
%let dsin=mv;
%let dsout=mv_id;
%let dsdup=duplicate_id;
%extunique(&dsin,&idvar,&dsout,&dsdup);


宏里面少了一段  还有几个代码写错了
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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