Write a macro program to find out how many ampersands is needed for generating the specified result.
Given a series of macro variables:
%let a=b;
%let b=c;
%let c=d;
%let d=e;
Pls help. Thank you.
What have you tried so far?
Hello,
What do you need that for ?
If you need more that three ampersands to resolve a macrovariable there
is probably a design problem in your code.
%let TRUE=GE;
%let GE=AND;
%let AND=LE;
%let LE=TRUE;
%macro MinAmpersand(var);
data _NULL_;
length value $4. amps $20.;
var="&var.";
amps="&";
do while (var ne value and MAX_LOOP<20);
MAX_LOOP+1;
value=resolve(cats(amps,"TRUE"));
amps=cats(amps,"&");
end;
nbamps=length(amps)-1;
put nbamps " ampersands necessary for macrovariable &var.";
run;
%mend;
%MinAmpersand(TRUE);
%MinAmpersand(GE);
%MinAmpersand(AND);
%MinAmpersand(LE);
I see a similar question has been asked here: https://communities.sas.com/t5/SAS-Procedures/Count-the-number-of-ampersands/m-p/518736#M73337
I can only assume it is some sort of homework assignment. Personally I don't see the value in these types of intellectual challenges.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.