BookmarkSubscribeRSS Feed
KeinYung
Calcite | Level 5

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.

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

What have you tried so far?

gamotte
Rhodochrosite | Level 12

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);
SASKiwi
PROC Star

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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