DATA Step, Macro, Functions and more

Concatenation with macro

Accepted Solution Solved
Reply
Super Contributor
Posts: 271
Accepted Solution

Concatenation with macro

 

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;

 


Accepted Solutions
Solution
‎03-31-2016 03:45 PM
Super User
Posts: 11,343

Re: Concatenation with macro

Posted in reply to SAS_inquisitive

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


All Replies
Solution
‎03-31-2016 03:45 PM
Super User
Posts: 11,343

Re: Concatenation with macro

Posted in reply to SAS_inquisitive

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.

Super User
Super User
Posts: 7,984

Re: Concatenation with macro

Posted in reply to SAS_inquisitive

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;
☑ This topic is solved.

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

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