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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 795 views
  • 0 likes
  • 2 in conversation