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;

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
  • 892 views
  • 1 like
  • 3 in conversation