具有宏阵列的sas扫描功能

时间:2018-03-06 02:53:16

标签: sas

我有一个宏数组& start_num

+-------+
| start |
+-------+
|  25.5 |
|  33.5 |
|  42.5 |
|  54.5 |
|    98 |
+-------+

但是当我使用

%put %scan(&start_num,1);

它返回:25

%put %scan(&start_num,2);

给我回复:533

为什么以及如何解决它?

2 个答案:

答案 0 :(得分:3)

您可以在scan函数中指定delimiter

例如,如果宏变量是从表中的变量start初始化的:

proc sql noprint;
   select start into:start_num separated by ' ' from have;
quit;
  

START_NUM = 25.5 33.5 42.5 54.5 98

或在%let语句中:

%let START_NUM=25.5 33.5 42.5 54.5 98;

使用%scan函数:

%let var1 = %scan(&start_num,1,%str( ));
%put &=var1;
  

VAR1 = 25.5

%let var2 = %scan(&start_num,2,%str( ));
%put &=var2;
  

VAR2 = 33.5

答案 1 :(得分:0)

因为%scan认为dot是分隔符,所以分别得到25和533。结帐以下示例

%let start_num= 25.533.545.554.598;
%let var1 = %scan(&start_num,1);
%put value of with dot as separator &var1;

%put& var1产生25

 %let var2 = %scan(&start_num,2);
 %put value of with dot as separator &var2;

%put& var2产生533