BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ivy
Quartz | Level 8 Ivy
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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

5 REPLIES 5
Reeza
Super User

What error do you get?

Patrick
Opal | Level 21

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(;) );
ballardw
Super User

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

 

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?

Ivy
Quartz | Level 8 Ivy
Quartz | Level 8

Dear all,

 

Thank you very much, 

%str()  works so beautifully !  🙂 

 

Ivy 

Patrick
Opal | Level 21

@Ivy

Then please mark one of the answers as correct answer

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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