楼主: happyzihao
3289 6

SAS跑完一段macro后log和explorer没有任何反应 [推广有奖]

  • 1关注
  • 2粉丝

博士生

68%

还不是VIP/贵宾

-

威望
0
论坛币
477 个
通用积分
0.0003
学术水平
1 点
热心指数
2 点
信用等级
1 点
经验
1738 点
帖子
322
精华
0
在线时间
342 小时
注册时间
2011-1-30
最后登录
2021-3-18

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
请教SAS 大神们,为什么这段Macro跑完 PSmatch 代码 log 没有任何反应呀... explore 里也没有新的数据集产生。

我一定犯了什么很低级的错误是不是....呜呜....





/********************************************************************************/
/* Program: PSMatch_Multi.sas
/*
/* Platform: SAS 9.1.3
/*
/* Drug/Protocol: Generalized SAS Macro
/*
/* Description: Does N:1 optimized propensity score matching within specified
/* absolute differences of propensity score
/********************************************************************************/
%macro psmatch_multi (pat_dsn =prop_score_treated, /* Name of data set with patient data */
                       pat_idvar=did, /* Name of Patient ID variable in data set &PAT_DSN */
                       pat_psvar=prob_treat, /* Name of Propensity Score variable in data set &PAT_DSN */
                       cntl_dsn= prop_score_untreated, /* Name of data set with control data */
                       cntl_idvar=did, /* Name of Control ID variable in data set &CNTL_DSN */
                       cntl_psvar=prob_treat, /* Name of Propensity Score variable in data set &CNTL_DSN */
                       match_dsn=matched_pairs, /* Name of output data set with N:1 matches */
                       match_ratio=1, /* Number of control matches per patient */
                       score_diff=0.001, /* Maximum allowable absolute differences between propensity scores*/
                       ) /* Optional input seed for random number generator */
                       ;

/**********************************************************************/
/* Delete final matched pairs dataset, if it exists from a prior run
/**********************************************************************/

proc datasets nolist;
     delete __final_matched_pairs;
     run;
     quit;

/********************************************/
/* Make all internal macro variables local
/********************************************/
%local __dsid __varnum __cntl_type __rc __num;

/***************************************************************************/
/* Determine characterisitcs of Control ID variable (numeric or character)
/***************************************************************************/
%let __dsid = %sysfunc(open(&cntl_dsn,i));
%let __varnum = %sysfunc(varnum(&__dsid, &cntl_idvar));
%let __cntl_type = %sysfunc(vartype(&__dsid, &__varnum));
%let __rc = %sysfunc(close(&__dsid));
%put &__cntl_type;

/**************************/
/* New director Matching Data
/**************************/

data __patmatch (keep = &pat_idvar &pat_psvar);
     set &pat_dsn;
     run;

/**************************/
/* Control Matching Data
/**************************/

data __contmatch (keep = &cntl_idvar &cntl_psvar);
     set &cntl_dsn;
     run;

/************************************************************/
/* Find all possible matches between directors and controls
/* Propensity scores must match within +/- &match
/************************************************************/
proc sql;
     create table __matches0 as
            select
            p.&pat_idvar as pat_idvar,
            c.&cntl_idvar as cntl_idvar,
            p.&pat_psvar as pat_score,
            c.&cntl_psvar as cntl_score
            from __patmatch p left join __contmatch c
            on abs(p.&pat_psvar - c.&cntl_psvar) <= &score_diff
            order by pat_idvar;
     quit;

/*************************************/
/* Data set of all possible matches
/*************************************/

data __possible_matches;
     set __matches0;

/*-----------------------------------------*/
/* Create a random number for each match
/*-----------------------------------------*/
rand_num = ranuni(&seed);

/*-----------------------------------------------*/
/* Remove patients who had no possible matches
/*-----------------------------------------------*/

%if &__cntl_type = C %then %do;
    if cntl_idvar ^= '';
%end;
%else %if &__cntl_type = N %then %do;
    if cntl_idvar ^= .;
%end;

/*---------------------------*/
/* Create a dummy variable
/*---------------------------*/

n = 1;

run;

/******************************************************************/
/* Find the number of potential control matches for each patient
/******************************************************************/

proc freq data=__possible_matches noprint;
     tables pat_idvar / out=__matchfreq (keep = pat_idvar count);
     run;

/****************************************************************************/
/* Optimize control matching for directors based on number of possible matches
/* Pick matches for directors with the fewest number of possible matches first
/****************************************************************************/

data __matches_freq0;
     merge __possible_matches
           __matchfreq;
     by pat_idvar;
     run;

/********************************************************************/
/* Find the number of potiential directors matches for each control
/********************************************************************/
proc freq data=__possible_matches noprint;
     tables cntl_idvar / out=__cntlfreq (keep = cntl_idvar count rename = (count = cntl_count));
     run;

proc sort data=__matches_freq0;
     by cntl_idvar;
     run;

data __matches_freq;
     merge __matches_freq0
           __cntlfreq;
     by cntl_idvar;

/*------------------------------------------------------*/
/* Take out directors with less than number of matches
/*------------------------------------------------------*/

if count >= &match_ratio;
run;

proc datasets nolist;
     delete __matches0;
     run;
     quit;

/*****************************************************************/
/* Count the number of entries in the file of possible matches
/*****************************************************************/
%let __dsid = %sysfunc(open(__matches_freq,i));
%let __num = %sysfunc(attrn(&__dsid,nobs));
%let __rc = %sysfunc(close(&__dsid));

%do %while (&__num >= 1);

proc sort data=__matches_freq;
     by count cntl_count rand_num pat_idvar;
     run;
/*********************************************************/
/* Get first randomly selected patient with the minimum
/* number of matches
/*********************************************************/

data __first_pat_idvar (keep = pat_idvar);
     set __matches_freq;
     by n;
     if first.n;
     run;

/******************************************************************/
/* Get all matches for that patient
/* Select the first randomly selected for the number of matches
/******************************************************************/
proc sort data=__matches_freq;
by pat_idvar count cntl_count rand_num;
run;

data __all_first_id;
     merge __matches_freq
           __first_pat_idvar (in=i);
     by pat_idvar;
     if i;
     num + 1;
     run;

data __new_matched_pairs (keep = pat_idvar cntl_idvar pat_score cntl_score);
     set __all_first_id;

     label pat_idvar = "Director ID, original variable name &dir_idvar"
     cntl_idvar = "Matched Control ID, original variable name &cntl_idvar"
     pat_score = "Director Propensity Score, original var name &pat_psvar"
     cntl_score = "Matched Control Propensity Score, orig var &cntl_psvar"
     ;
     if num <= &match_ratio;
     run;
/******************************************/
/* Remove directors with matched controls
/******************************************/
proc sort data=__new_matched_pairs (keep = pat_idvar)
          out=__new_matched_pats nodupkey;
          by pat_idvar;
          run;

data __match_remove_pat;
     merge __possible_matches
           __new_matched_pats (in=id);
     by pat_idvar;
     if ^id;
     run;

/************************************************************/
/* Remove all matched pairs that include selected controls
/************************************************************/
proc sort data=__new_matched_pairs (keep = cntl_idvar) out=__remove_cont;
     by cntl_idvar;
     run;

proc sort data=__match_remove_pat;
     by cntl_idvar;
     run;

data __match_remove_cont;
     merge __match_remove_pat
           __remove_cont (in=id);
     by cntl_idvar;
     if ^id;
     run;
proc sort data=__match_remove_cont out=__possible_matches;
     by pat_idvar;
     run;

/********************************************************/
/* Add new matched pairs to set of final matched pairs
/********************************************************/

proc append base=__final_matched_pairs data=__new_matched_pairs;
     run;

/******************************************************************/
/* Find the number of potential control matches for each patient
/******************************************************************/

proc freq data=__possible_matches noprint;
     tables pat_idvar / out=__matchfreq (keep = pat_idvar count);
     run;

/***************************************************************************/
/* Optimize control matching for patients based on number of possible matches
/* Pick matches for patients with the fewest number of possible matches first
/***************************************************************************/

data __matches_freq0;
     merge __possible_matches
           __matchfreq;
     by pat_idvar;
     run;

/********************************************************************/
/* Find the number of potential patient matches for each control
/********************************************************************/

proc freq data=__possible_matches noprint;
     tables cntl_idvar / out=__cntlfreq (keep = cntl_idvar count rename = (count = cntl_count));
     run;

proc sort data=__matches_freq0;
     by cntl_idvar;
     run;

data __matches_freq;
     merge __matches_freq0
           __cntlfreq;
     by cntl_idvar;

/*------------------------------------------------------*/
/* Take out directors with less than number of matches
/*------------------------------------------------------*/

if count >= &match_ratio;
run;

/********************************************************/
/* Determine number of remaining possible matched pairs
/********************************************************/

  %let __dsid = %sysfunc(open(__matches_freq,i));
  %let __num = %sysfunc(attrn(&__dsid,nobs));
  %let __rc = %sysfunc(close(&__dsid));

%end; /* of " %do %while (&__num >= 1); */


/********************************************************************************/
/* Create final output data set with one observation for each original patient
/* ID Variable names in output data set are PAT_IDVAR, PAT_SCORE, CNTL_IDVAR,
/* CNTL_SCORE
/* If no match for patient ID (PAT_IDVAR), then corresponding CNTL variables
/* (CNTL_IDVAR, CNTL_SCORE) are missing.
/********************************************************************************/

proc sort data=__final_matched_pairs;
by pat_idvar pat_score;
run;

data __patmatch_orig;
set __patmatch (rename= (&pat_idvar = pat_idvar &pat_psvar = pat_score));
run;

proc sort data=__patmatch_orig;
by pat_idvar;
run;

data &match_dsn (label = "Final Matched Pairs for Propensity Score Matching");
merge __final_matched_pairs
      __patmatch_orig;
by pat_idvar pat_score;
run;

/***************************************************/
/* Delete all temporary datasets created by macro
/***************************************************/

proc datasets nolist;
delete __contmatch __final_matched_pairs __matches_freq0 __matches_freq
       __match_pair0 __matchfreq __match_remove_cont __match_remove_pat
       __new_matched_pairs __patmatch __patmatch_orig __possible_matches
       __remove_cont __cntlfreq __first_pat_idvar __all_first_id
       __new_matched_pats;
       run;
       quit;
%mend psmatch_multi;


二维码

扫码加我 拉你入群

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

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

关键词:explorer Explore Xplore Macro acr SAS MACRO

沙发
zhanzhang1 发表于 2015-8-18 22:49:45 |只看作者 |坛友微信交流群
这些代码看了就头痛14391306490387.gw.1688.com 14393815455838.gw.1688.com
14391728765960.gw.1688.com 14393833665826.gw.1688.com
14390404703492.gw.1688.com 14393852222244.gw.1688.com
14392188700201.gw.1688.com 14394576958385.gw.1688.com
14392206909969.gw.1688.com 14395567723151.gw.1688.com

使用道具

藤椅
shaode01 学生认证  发表于 2015-8-18 23:30:07 来自手机 |只看作者 |坛友微信交流群
happyzihao 发表于 2015-8-18 22:41
请教SAS 大神们,为什么这段Macro跑完 PSmatch 代码 log 没有任何反应呀... explore 里也没有新的数据集产生 ...
麻烦你把产生datasets的宏代码单独拎出来跑一下,如果出错再来提问好吗

使用道具

板凳
wpfwxn 发表于 2015-8-19 07:13:55 来自手机 |只看作者 |坛友微信交流群
shaode01 发表于 2015-8-18 23:30
麻烦你把产生datasets的宏代码单独拎出来跑一下,如果出错再来提问好吗
把sas关了,重新run

使用道具

报纸
happyzihao 发表于 2015-8-19 11:03:32 |只看作者 |坛友微信交流群
shaode01 发表于 2015-8-18 23:30
麻烦你把产生datasets的宏代码单独拎出来跑一下,如果出错再来提问好吗
Don't be annoyed...

我就是对宏代码太不了解....不知道怎么拎出来跑... 所以才对着一大坨不知道怎么办好...

使用道具

地板
shaode01 学生认证  发表于 2015-8-21 19:51:12 |只看作者 |坛友微信交流群
这段代码从
%macro psmatch_multi (.....)
这里开始进行宏函数定义

%mend psmatch_multi;
宏函数定义结束。
结束后你并未调用这个宏函数,所以这个宏函数就没有执行,当然什么也不会产生啦。
QQ截图20150821195017.jpg
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
happyzihao + 5 + 2 + 2 + 2 精彩帖子

总评分: 论坛币 + 5  学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

使用道具

7
happyzihao 发表于 2015-8-22 17:00:05 |只看作者 |坛友微信交流群
shaode01 发表于 2015-8-21 19:51
这段代码从
%macro psmatch_multi (.....)
这里开始进行宏函数定义
谢谢你!真是秒解决!

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-30 18:12