BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10

 

In this example what is the purpose of comma (",age,") in the concatenation function (cats).

 

 

%macro mymacro(age=0);

	proc sql noprint;
		select quote(name) into :namelist separated by ',' 
           from sashelp.class where age=&age.;
	quit;

	data name_age;
		set sashelp.class;
		where name in (&namelist.);
	run;

	proc print data=name_age;
		var name age;
	run;

%mend mymacro;

proc sort data=sashelp.class out=class nodupkey;
	by age;
run;

data _null_;
	set class;
	exec_val = cats('%mymacro(age=',age,')');
	call execute(exec_val);
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The comma separates the values that are to be concatenated. In this case the values are:

'%mymacro(age=

The value of the variable age

')'

 

to make a string that could be

%mymacro(age=23)

as the call to the macro when the data _null_ step terminates.

View solution in original post

2 REPLIES 2
ballardw
Super User

The comma separates the values that are to be concatenated. In this case the values are:

'%mymacro(age=

The value of the variable age

')'

 

to make a string that could be

%mymacro(age=23)

as the call to the macro when the data _null_ step terminates.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Out of interest, why all the code?  It basically distills down to:

proc sort data=sashelp.class out=class;
  by age;
run;
proc print data=class;
  by age;
run;

Or worse case scenario:

proc sort data=sashelp.class out=class nodupkey;
  by age;
run;
data _null_;
set class;
call execute(cat('proc print data=sashelp.class; where age=',strip(put(age,best.)),';run;');
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1414 views
  • 1 like
  • 3 in conversation