从 libname 调用宏变量
Calling a macro variable from libname
如果我想在 libname 中使用宏变量,如何在 proc sql 的 from 子句中调用它?
让我告诉你我的意思:
options nofmterr;
libname FRST "/ecm/retail/mortgage/nbk6kra/LGD/data/frst_201312bkts";
libname HELN "/ecm/retail/mortgage/nbk6kra/LGD/data/heln_201312bkts";
libname HELC "/ecm/retail/mortgage/nbk6kra/LGD/data/helc_201312bkts";
%let pathLGD = /new/mortgage/2014Q4/LGD;
%let prod = FRST;
/**************** Segment calculation **************** Date filter to be consistent with model documentation for segmented tables****************/
%macro Performance(prod);
proc sql;
create table lgd_seg_&prod as
select distinct
SegDT_LGD_2013,
min(ScoreDT_LGD_2013) as min_range,
max(ScoreDT_LGD_2013) as max_range,
count(*) as count,
mean(lgd_ncl_adjusted) as LGD_actual,
mean(ScorePIT_LGD_2013) as LGD_pred_pit_1,
mean(ScoreDT_LGD_2013) as LGD_pred_dt_1
from "&prod."scored;
where coh_asof_yyyymm > 200612
group by 1;
quit;
PROC EXPORT DATA=lgd_seg_&prod._fs
OUTFILE= "&pathLGD./lgd_seg.xlsx"
DBMS=XLSX REPLACE;
SHEET="&prod._lgd_seg_fs";
RUN;
%mend;
%Performance(prod=FRST);
%Performance(prod=HELN);
%Performance(prod=HELC);
因此在 "from" 子句中,宏应该分别读取 FRST.scored、HELN.scored 和 HELC.scored。目前它找不到文件,如果我去掉引号,它就会变成"work.FRSTscored"。
我希望我已经说清楚了。欢迎任何输入和评论。
当你想在一个宏变量的解析值后面加上一个直接的附加字符时,你应该用句号转义宏变量 (.
)。例如:
%let start = one;
%put &start.two;
%put &start..two;
%put &startend;
onetwo
one.two
WARNING: Apparent symbolic reference STARTEND not resolved.
因此您的代码应显示为 from &prod..scored;
。
如果需要,您还可以使用双符号 (&&
) 延迟宏变量的解析:
%let end = two;
%let onetwo = three;
%put &&one&end;
%put &&&start&end;
Three
Three
或者:
%let three = inception;
%put &&&&&&&start&end;
inception
删除宏变量 prod 外的引号,并在宏变量后使用两个点(一个表示宏变量名称的结尾,第二个用于指定 libname 引用后的 table 名称。
from &prod..scored
如果我想在 libname 中使用宏变量,如何在 proc sql 的 from 子句中调用它? 让我告诉你我的意思:
options nofmterr;
libname FRST "/ecm/retail/mortgage/nbk6kra/LGD/data/frst_201312bkts";
libname HELN "/ecm/retail/mortgage/nbk6kra/LGD/data/heln_201312bkts";
libname HELC "/ecm/retail/mortgage/nbk6kra/LGD/data/helc_201312bkts";
%let pathLGD = /new/mortgage/2014Q4/LGD;
%let prod = FRST;
/**************** Segment calculation **************** Date filter to be consistent with model documentation for segmented tables****************/
%macro Performance(prod);
proc sql;
create table lgd_seg_&prod as
select distinct
SegDT_LGD_2013,
min(ScoreDT_LGD_2013) as min_range,
max(ScoreDT_LGD_2013) as max_range,
count(*) as count,
mean(lgd_ncl_adjusted) as LGD_actual,
mean(ScorePIT_LGD_2013) as LGD_pred_pit_1,
mean(ScoreDT_LGD_2013) as LGD_pred_dt_1
from "&prod."scored;
where coh_asof_yyyymm > 200612
group by 1;
quit;
PROC EXPORT DATA=lgd_seg_&prod._fs
OUTFILE= "&pathLGD./lgd_seg.xlsx"
DBMS=XLSX REPLACE;
SHEET="&prod._lgd_seg_fs";
RUN;
%mend;
%Performance(prod=FRST);
%Performance(prod=HELN);
%Performance(prod=HELC);
因此在 "from" 子句中,宏应该分别读取 FRST.scored、HELN.scored 和 HELC.scored。目前它找不到文件,如果我去掉引号,它就会变成"work.FRSTscored"。 我希望我已经说清楚了。欢迎任何输入和评论。
当你想在一个宏变量的解析值后面加上一个直接的附加字符时,你应该用句号转义宏变量 (.
)。例如:
%let start = one;
%put &start.two;
%put &start..two;
%put &startend;
onetwo
one.two
WARNING: Apparent symbolic reference STARTEND not resolved.
因此您的代码应显示为 from &prod..scored;
。
如果需要,您还可以使用双符号 (&&
) 延迟宏变量的解析:
%let end = two;
%let onetwo = three;
%put &&one&end;
%put &&&start&end;
Three
Three
或者:
%let three = inception;
%put &&&&&&&start&end;
inception
删除宏变量 prod 外的引号,并在宏变量后使用两个点(一个表示宏变量名称的结尾,第二个用于指定 libname 引用后的 table 名称。
from &prod..scored