来自其他宏变量的宏变量
Macro variable from other macro variable
假设我想创建一个像这样的宏变量:
%let year=2019;
%let ye = SUBSTR(%year,3,2) (I want to extract 19 from 2019).
但是不行。我们有没有像这样创建这样的宏变量?
更新:我的代码实际上是这样的
%let yearend = 2019
% let monthend = 04
现在我想创建一个像 "data1904" 这样的宏变量,以便在我的库中使用名为 "data1904" 的数据集。所以我想创建的是
%let dataname= CAT(SUBSTR(%yearend,3,2),%monthend)
您使用 & 来引用宏变量,而不是 %。
在宏代码中使用函数时,需要将其包装在 %SYSFUNC()
中,以便编译器可以 differentiate between text and code.
%let ye = %sysfunc(substr(&year, 3, 2));
或者还有 %SUBSTR()
宏 function,它允许您跳过 %SYSFUNC()。
%let ye = %substr(&year, 3, 2);
假设我想创建一个像这样的宏变量:
%let year=2019;
%let ye = SUBSTR(%year,3,2) (I want to extract 19 from 2019).
但是不行。我们有没有像这样创建这样的宏变量?
更新:我的代码实际上是这样的
%let yearend = 2019
% let monthend = 04
现在我想创建一个像 "data1904" 这样的宏变量,以便在我的库中使用名为 "data1904" 的数据集。所以我想创建的是
%let dataname= CAT(SUBSTR(%yearend,3,2),%monthend)
您使用 & 来引用宏变量,而不是 %。
在宏代码中使用函数时,需要将其包装在 %SYSFUNC()
中,以便编译器可以 differentiate between text and code.
%let ye = %sysfunc(substr(&year, 3, 2));
或者还有 %SUBSTR()
宏 function,它允许您跳过 %SYSFUNC()。
%let ye = %substr(&year, 3, 2);