如何在 SAS 中的 libname 语句的引用字符串内调用宏变量
我有一个每年都不同的库名称,我想制作一个程序来自动调整这一点。但为了让一切正常工作,我必须在 libname 语句中引用的字符串内调用宏。我该怎么做?
%macro srvyr;
data work.whatever;
length srvyr $4.;
srvyr = (left(year(date()))-1);
srvyr2 = "'C:\Documents and Settings\user\Desktop\sas\d"||srvyr||"a1'";
run;
%mend;
%srvyr;
/*Everything above sets configures the pathname the way I need it*/
我想然后运行这个:
libname stuff &srvyr;run;
就好像它是
libname stuff 'C:\Documents and Settings\user\Desktop\sas\d2010a1';
run;
我该怎么做?
I have a libname that varies from year to year and I wanted to make a program that automatically adjusts for this. But in order for everything to work I have to have invoke a macro inside of the quoted string in a libname statement. How do I do this?
%macro srvyr;
data work.whatever;
length srvyr $4.;
srvyr = (left(year(date()))-1);
srvyr2 = "'C:\Documents and Settings\user\Desktop\sas\d"||srvyr||"a1'";
run;
%mend;
%srvyr;
/*Everything above sets configures the pathname the way I need it*/
I want to then run this:
libname stuff &srvyr;run;
as if it were
libname stuff 'C:\Documents and Settings\user\Desktop\sas\d2010a1';
run;
How do I do this right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是否始终必须是前一年,或者您是否希望将其基于数据集中的值。你不需要宏来解决这个问题。
获取去年的最短方法如下
,如果您想将其分解以使其更具可读性,则可以像这样
Does is always have to be the previous year, or do you want to base it on a value in a dataset. You don't need macro to solve this.
The shortest method to get last year is as follows
and if you want to break it up to make it more readable it could be like this
call symput
是你的朋友。创建变量 srvyr2: 之后,将以下内容放入数据步骤内,然后放在宏外部,
call symput
is your friend. Put the following inside the data step, after creating the variable srvyr2:and then outside the macro,