The find function is not working ????
%macro find_example1();
%let my_string =This is a test string;
%let substring =test;
%let position = %sysfunc(find(&my_string, &substring));
%put Position = &position; /* Expected output: Position = 11 */
%mend;
%find_example1;
%macro find_example2();
%let my_string ="This is a test string;";
%let substring ="test";
%let position = %sysfunc(find(&my_string, &substring));
%put Position = &position; /* Expected output: Position = 11 */
%mend;
%find_example2;
How to solve this issue
I think you need some & ampersands.
65 %macro find_example1(); 66 %let my_string =This is a test string; 67 %let substring =test; 68 %let position = %sysfunc(find(&my_string, &substring)); 69 %put Position = &position; /* Expected output: Position = 11 */ 70 %mend; 71 72 %find_example1; Position = 11 73 74 %macro find_example2(); 75 %let my_string ="This is a test string;"; 76 %let substring ="test"; 77 %let position = %sysfunc(find(&my_string, %sysfunc(dequote(&substring)))); 78 %put Position = &position; /* Expected output: Position = 11 */ 79 %mend; 80 81 %find_example2; Position = 12
I think you need some & ampersands.
65 %macro find_example1(); 66 %let my_string =This is a test string; 67 %let substring =test; 68 %let position = %sysfunc(find(&my_string, &substring)); 69 %put Position = &position; /* Expected output: Position = 11 */ 70 %mend; 71 72 %find_example1; Position = 11 73 74 %macro find_example2(); 75 %let my_string ="This is a test string;"; 76 %let substring ="test"; 77 %let position = %sysfunc(find(&my_string, %sysfunc(dequote(&substring)))); 78 %put Position = &position; /* Expected output: Position = 11 */ 79 %mend; 80 81 %find_example2; Position = 12
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.