BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sathya66
Barite | Level 11

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

2 REPLIES 2
Astounding
PROC Star

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.

PaigeMiller
Diamond | Level 26

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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