Search code examples
sassas-macro

Position of a word/var in a list SAS


This might be a rather simple question but I am new to SAS and am clueless even after researching on this in Google.

I have a macro variable as -

%let list = 12AUG2013 13AUG2013 15AUG2013 16AUG2014 09SEPT2014;

I need to get the following things -

a) Total words in list: In R this would be length(list). But in SAS, length counts each character. COUNTW does not work. Anyway I can do this?

b) Finding the ith word: If I need the 3rd element in this list, I would say list[3] in R. How can I do that in SAS?

c) Finding the position of an element: Suppose I need to know which position 16AUG2014 is at in the list variable, how can I get it?

Thanks for all the help!


Solution

  • The Code for position in list is

    %let list_pos=%sysfunc(countw(%substr(&list,1,%index(&list,16AUG2014)+1)));  
    

    Cheers