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

Hi Experts,

I have a problem getting numeric values for a Macro variable in a do loop. Example codes are:

%Macro abcd(aa=0.44 0.3 2 1, st=1, ed=4);

data abc;
M=1;
V=100;

%do i=&st %to &ed;
%LET wt=%scan(&aa, &i);
MT=M+V; output;
%PUT &wt;
%END;
RUN;

%MEND;

%abcd;

 

I am getting values 0, 44, 0, 3 instead of 0.44, 0.3, 2, 1. Please help me getting the correct value for each iteration.

Thank you

Hitesh

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You probably need the third argument in the %SCAN function to indicate that a space is the delimiter.

 

%LET wt=%scan(&aa, &i, %str( ));
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You probably need the third argument in the %SCAN function to indicate that a space is the delimiter.

 

%LET wt=%scan(&aa, &i, %str( ));
--
Paige Miller
Hitesh
Fluorite | Level 6

Thank you very much Paige, You saved my day!

Hitesh
Fluorite | Level 6

Hi Kurt,

It was just sample code. I am using that to provide different weights to different year data in my actual macro where these values need to provide by user and can vary for each year.

Thanks for the response.

Hitesh

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 771 views
  • 3 likes
  • 3 in conversation