DATA Step, Macro, Functions and more

macro not resolving in loop

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 76
Accepted Solution

macro not resolving in loop

Hi All,

it has to create 

sashelp

aa

dd

ss

dd data sets but macro is not resolving.

Thanks,

S

data test;
infile cards;
input a$;
cards;
sashelp
aa
dd
ss
dd
;
run;

proc sql noprint;
	select count(*) into :numb
	from test;
	;
quit;
%macro a;
%do i=1 %to &numb.;
	data _null_;
	set test (firstobs=&i obs=&i);
	call symput("a&&i",trim(left(a)));
	run;
	data work.&a&i._01;
	  set sashelp.class;
	  run;
	  %end;
%mend;

%a;

 


Accepted Solutions
Solution
‎03-29-2018 09:14 AM
Super User
Posts: 6,939

Re: macro not resolving in loop

This line is wrong:

 

data work.&a&i._01;

 

It should be:

 

data work.&&a&i.._01;

 

This piece won't cause an error, but is mildly misleading:

 

call symput("a&&i", trim(left(a)));

 

It should become:

 

call symputx("a&i", a);

 

Only one ampersand is needed, and switching to SYMPUTX removes all leading and trailing blanks.

View solution in original post


All Replies
Solution
‎03-29-2018 09:14 AM
Super User
Posts: 6,939

Re: macro not resolving in loop

This line is wrong:

 

data work.&a&i._01;

 

It should be:

 

data work.&&a&i.._01;

 

This piece won't cause an error, but is mildly misleading:

 

call symput("a&&i", trim(left(a)));

 

It should become:

 

call symputx("a&i", a);

 

Only one ampersand is needed, and switching to SYMPUTX removes all leading and trailing blanks.

Respected Advisor
Posts: 3,294

Re: macro not resolving in loop

[ Edited ]

You have too many & in your code.

 

Replace the lines you typed with these

 

call symputx("a&i",a);

and

data work.a&i._01;

Hint: debugging these things is much easier if your code begins with

 

options mprint;
--
Paige Miller
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 98 views
  • 0 likes
  • 3 in conversation