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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.