DATA Step, Macro, Functions and more

Macro program

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 76
Accepted Solution

Macro program

Hello,

 

When I put the following Macro statments in a loop in Macro program, it gave me error , however, I can run by itself without probelm. I I am wondering what is the problem.

 Thank you. 

 

%let medlist = %str("cisplatin" ; "carboplatin"; "paclitaxel" ; "paclitaxel protein-bound" ; "pemetrexed disodium"; "ramucirumab"; "bevacizumab" ; "pembrolizumab" ; "nivolumab" ; "necitumumab" );
%let med = %scan(&medlist, 8 , ; );

 

%macro test1;
%let medlist = %str("cisplatin" ; "carboplatin"; "paclitaxel" ; "paclitaxel protein-bound" ; "pemetrexed disodium"; "ramucirumab"; "bevacizumab" ; "pembrolizumab" ; "nivolumab" ; "necitumumab" );
%do i =1 %to 10 ;
%let med = %scan(&medlist, &i , ; );
%put  &med ;
%end;

%mend;

 

%test1;


Accepted Solutions
Solution
‎01-07-2017 11:51 AM
Respected Advisor
Posts: 3,894

Re: Macro program

[ Edited ]

NOTE: One or more missing close parentheses have been supplied for the %SCAN function.

 

Put the ; delimiter into a %str() function so it doesn't get interpreted as end of command indicator.

    %let med = %scan(&medlist, &i , %str(;) );

View solution in original post


All Replies
Super User
Posts: 17,852

Re: Macro program

What error do you get?

Solution
‎01-07-2017 11:51 AM
Respected Advisor
Posts: 3,894

Re: Macro program

[ Edited ]

NOTE: One or more missing close parentheses have been supplied for the %SCAN function.

 

Put the ; delimiter into a %str() function so it doesn't get interpreted as end of command indicator.

    %let med = %scan(&medlist, &i , %str(;) );
Super User
Posts: 10,514

Re: Macro program

%let med = %scan(&medlist, &i , %str(Smiley Wink );

 

The "bare" semicolon is treated as a statement ender. I would consider use of a ; as a delimiter a poor choice for working with SAS code. Is there a specific reason you used that?

Frequent Contributor
Frequent Contributor
Posts: 76

Re: Macro program

Dear all,

 

Thank you very much, 

%str()  works so beautifully !  :-) 

 

Ivy 

Respected Advisor
Posts: 3,894

Re: Macro program

@Ivy

Then please mark one of the answers as correct answer

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 254 views
  • 0 likes
  • 4 in conversation