我想在%let調用中使用宏,下面是宏代碼以及我想如何調用它。請幫我實現它。如何在%let中使用SAS宏調用
%macro xscan(string, delimiter, word_number);
%let len1=%length(&string); /*Computing the length of the string*/
%let len=%eval(&len1+1);
%let sub=%scan(&string,&word_number,"&delimiter"); /*Fetch the string specified by word_number*/
%if &word_number ge 0 %then %do;
%let pos=%index(&string,&sub); /* Locate the position while reading left to right*/
%end;
%if &word_number lt 0 %then %do;
data _null_;
pos=find("&string","&sub",-&len); /* Locate the position while reading from right to left*/
call symput("pos",pos);
run;
%end;
%let strg=%substr(&string,&pos); /* Extract the substring*/
%put the string is &strg;
%mend;
%let sub_str = %xscan(a bb ccc dddd bb eeeee, %str(), -2);
%put The value of sub_str = &sub_str;
期望的實現:
data work.in_data;
length in_string $50;
in_string = 「a bb ccc dddd bb eeeee」;
output;
in_string = 「aa b cc aa dee」;
output;
run;
data work.out_data;
set work.in_data;
length sub_str $50;
start_word_num = -(_n_ +1);
sub_str = %xscan(in_string,’ ‘, start_word_num);
run;
proc print; run;
給出了一些代碼,但問題的本質並不明確。請澄清你的問題。 – CSJ
呃,它可能會更清晰,但問題標題其實很清晰(而且是問題)給SAS程序員。 – Joe