BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

View solution in original post

1 REPLY 1
data_null__
Jade | Level 19

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 890 views
  • 0 likes
  • 2 in conversation