In the below macro code value of macro variable 'entity_cd' resolves to 1234,5678 and so I've got the error '
ERROR: Macro function %INDEX has too many arguments.'
I would like to know how to pass the aruguments as loop in index function, so that in first Iteration it will check for the value 1234 and in next Iteration it will check for 5678. Any help to resolve this error?
%if cmpnt='LDAT' and %index(&file_name.,&entity_cd.) > 0 %then %do; %let cnt=%eval(&cnt. + 1); %end;
It's not really a fair question. After all, this comparison will never be true:
%if cmpnt='LDAT' %then %do;
Never ever.
I would suggest you do more of the work. Get code that is working except for the piece that you want fixed. Otherwise, you're really just asking someone else to do your work for you by finding all the errors and fixing them.
@David_Billa wrote:
You can ignore the first %if clause in my post. I would like to understand
how to loop the values as argument in %index function.
Hint: write non-macro code first that does what you want in this situation. Once you have that working, you can keep the parts that don't change, and insert macro variables for the parts that do change.
Try using the SCAN() function within a loop. Here's an example that should get you headed in the right direction:
%let macro_var = 123,456,789;
%let dummy_file_name = abc_123_def_456;
data _null_;
count = countw("¯o_var",',');
do i = 1 to count;
string = scan("¯o_var.",i);
if index("&dummy_file_name", strip(string)) > 0
then put "Code to execute, since " string " is in &dummy_file_name.";
else put "Otherwise...";
end;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: