'SAS how to slice and loop through a VARCHAR

I would like to slice and loop through a VARCHAR this is what I try :

%MACRO test;

data
     %DO i_=1 %TO 4;

          %LET extract&i_.=%SCAN(&string.,&i_.," ");
          %PUT extract&i_.=&&extract&i_.._hash;

     %END;
%MEND test;

this work but the problem is that I have to put the number of words in my code for exemple here it's 4 but if I have a new string with 5 or 6 words this doesn't work.

sas


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source