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

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1166 views
  • 3 likes
  • 3 in conversation