避免将标点符号作为列表

时间:2015-05-11 07:45:09

标签: sas

我有一个我要循环的列表(频率)。示例列表:

%let Freq_list = min5 min2 sec60.31 sec30; 

默认情况下,SAS会在" sec60.31"中处理标点符号。作为分隔符。如何避免在列表中使用标点符号("。")作为分隔符?

我想遍历这个频率列表,然后想要" sec60.31"成为从列表中提取的一个这样的成员。

更多代码(程序的一部分):

%let n_f = %sysfunc(countw(&freqlist));

%do I_f=1 %to &n_f;
%let freq = %scan(&freqlist,&I_f);
%let freqtext = %scan(&freqtextlist,&I_f);
proc timeseries data=[datafile] out= [datafile]_&freqtext.;
where weekday between 2 and 6;
id datetime interval=&freq accumulate=last setmissing=missing align=beg start = '01jan1999.00:05'dt end = '01dec2014.00:00'dt;
var price;
run;
%end;

结果是它使用" interval = sec60"运行PROC TIMESERIES,然后在涉及" 31" -part:

时产生以下错误
NOTE: Line generated by the macro variable "FREQ".
1     31
      --
      22
      200
ERROR 22-322: Syntax error, expecting one of the following: a name, a format name.
ERROR 200-322: The symbol is not recognized and will be ignored.

计数器& n_f表示COUNTW功能处理"。"作为分隔符所以我想我都需要COUNTW函数和SCAN函数来识别分隔符。

您可能已经注意到我在文件名等中使用了另一个列表。

%let Freq_textlist = min5 min2 min1 sec30; 

我的问题的一个解决方案可能是从此列表中获取counter& n_f(长度相等),并将我的freq_list更改为:

%let Freq_list = min5@min2@sec60.31@sec30; 

并使用%scan和delimiter-paramter,如:

%let freq = %scan(&freqlist,&I_f,@);

这无需处理COUNTW如何识别"。"不是分隔符。

1 个答案:

答案 0 :(得分:0)

使用%scan()宏函数循环宏变量中的元素时,可以明确指定分隔符作为第三个参数。

以下声明将输出' sec30':

%put %scan(&Freq_list.,4,' ');