【发布时间】:2020-11-04 22:22:27
【问题描述】:
在我的项目中,我接受用户输入,其中一个变量是提取的关键。这个变量是年份,但可以为某些数据集编写,例如“Graduation_year”,而在其他数据集中可能是“Year_of_purchase”等等。我需要做的是将此变量从列表中取出,以便与列表的其余部分分开使用。从下面的示例中,我想要的结果如下所示: 输入 -> (Gender Graduation_Year Course_Name) 输出 -> Var_of_importance = Graduation_year 和 Remainder_vars= Gender Course_name。
到目前为止,我使用的代码遇到了一个错误,因为我试图在称为 size 的第二个循环的每次迭代中更新一个宏变量。
代码如下:
%macro Year_finder(var_list);
%local size;
%Put The variables are: &var_list.;
%let Keyword_loc=%Index(&var_list.,Year);
%put The location of the keyword Year begins at place number &Keyword_loc.;
%do i=1 %to %sysfunc(countw(&var_list.));
%let word_&i.=%length(%sysfunc(scan(&var_list.,&i.)));
%put The length of %sysfunc(scan(&var_list.,&i.)) is &&word_&i.;
%end;
%do i=1 %to %sysfunc(countw(&var_list.));
%if i=1 %then %do;
%if &&word_&i. LT &Keyword_loc. and &&word_(&i.+1)+1 GT &Keyword_loc. %then Word = %sysfunc(scan(&var_list.,&i.));
%let size=&&word_&i.;
%put The step number is step &i.;
%put The &i.th word has a length of &&word_&i.;
%put Initial length is &size.;
%end;
%else %do;
%eval(&size. = &size.+ &&word_&i. + 1);
%if &size. LT &Keyword_loc. and &size. + &&word_(&i.+1) + 1 GT &Keyword_loc. %then Word = %sysfunc(scan(&var_list.,(&i.+1)))
%put This step number is step &i.;
%put The length variable = &size.;
%put The word is &Word.;
%end;
%end;
%mend;
%Year_finder(Gender Graduation_Year Course_Name);
目前这似乎会做我想做的事,但由于我无法克服这个错误,我无法验证它是否有效。任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: compiler-errors sas macros sas-macro