如何在 SAS 中的 libname 语句的引用字符串内调用宏变量

发布于 2024-10-21 02:37:53 字数 602 浏览 7 评论 0原文

我有一个每年都不同的库名称,我想制作一个程序来自动调整这一点。但为了让一切正常工作,我必须在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你对谁都笑 2024-10-28 02:37:53

是否始终必须是前一年,或者您是否希望将其基于数据集中的值。你不需要宏来解决这个问题。

获取去年的最短方法如下

libname stuff "C:\Documents and Settings\user\Desktop\sas\d%eval(%sysfunc(year(%sysfunc(date())))-1)a1";

,如果您想将其分解以使其更具可读性,则可以像这样

%let lastyear = %eval(%sysfunc(year(%sysfunc(date())))-1);
%let libpath = C:\Documents and Settings\user\Desktop\sas\d&lastyear.a1;

libname stuff "&libpath";

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

libname stuff "C:\Documents and Settings\user\Desktop\sas\d%eval(%sysfunc(year(%sysfunc(date())))-1)a1";

and if you want to break it up to make it more readable it could be like this

%let lastyear = %eval(%sysfunc(year(%sysfunc(date())))-1);
%let libpath = C:\Documents and Settings\user\Desktop\sas\d&lastyear.a1;

libname stuff "&libpath";
空心空情空意 2024-10-28 02:37:53

call symput 是你的朋友。创建变量 srvyr2: 之后,将以下内容放入数据步骤内,

call symput('srvyr_path', srvyr2);

然后放在宏外部,

libname stuff &srvyr_path;

call symput is your friend. Put the following inside the data step, after creating the variable srvyr2:

call symput('srvyr_path', srvyr2);

and then outside the macro,

libname stuff &srvyr_path;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文