Dear Community,
My macro is looping through an array of numbers.
%let cutoff = 90 95 96 96.5;
The macro works just fine for the integers, but not for the numbers with decimal marks. For 96.5, the macro thinks that it is 2 separate numbers - 96 and 5.
The %STR and %NRSTR functions do not mask periods.
How can I make the macro to recognize 96.5 properly?
I think that a masking macro function is needed, but I can't fine one.
Thanks,
Eric
You will need to provide more about how you are using the values.
Perhaps you are using the %SCAN() function? The default delimiters for %SCAN() do include a period, but you can specify the delimiters you want to use.
%let cutoff = 90 95 96 96.5;
%do i=1 %to %countw(&cutoff,%str( ));
%let value=%scan(&cutoff,&i,%str( ));
...
%end;
Hi,
I have created a dummy dataset by using the macro variable with the values provided and it has created a dataset without any problem. Could you please check the below code and let me know if this is not the way you want to use it.
%let cutoff = 90 95 96 96.5;
%put &cutoff;
data have;
array mac(4) (&cutoff);
do i = 1 to 4;
new=mac(i);
output;
end;
run;
Thanks,
Jag
You will need to provide more about how you are using the values.
Perhaps you are using the %SCAN() function? The default delimiters for %SCAN() do include a period, but you can specify the delimiters you want to use.
%let cutoff = 90 95 96 96.5;
%do i=1 %to %countw(&cutoff,%str( ));
%let value=%scan(&cutoff,&i,%str( ));
...
%end;
Ahh...yes, thank you, Tom. I did not specify the delimiter when I used %SCAN(). Once I corrected that with %STR( ), the macro worked.
Thank you!
And thank you, Jagadishkatam, for providing your sample code!
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!
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.