BookmarkSubscribeRSS Feed
David_Billa
Rhodochrosite | Level 12

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;
4 REPLIES 4
Astounding
PROC Star

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
Rhodochrosite | Level 12
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.
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
mklangley
Lapis Lazuli | Level 10

 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("&macro_var",',');
    do i = 1 to count;
        string = scan("&macro_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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 634 views
  • 2 likes
  • 4 in conversation