I have a macro:
%generate_string();
%let string= apple;
%put &string;
%mend;
I have a data step where I have to concatenate a value with this macro output:
data _null_;
%let output = This is an || %generate_string() ||.;
%put &output;
run;
I need output as :
This is an apple.
%macro generate_string;
%global string;
%let string= apple;
&string
%mend;
data _null_;
output = "This is an"||" "||"%generate_string"||".";
put output=;
run;
%macro generate_string;
%global string;
%let string= apple;
&string
%mend;
data _null_;
output = "This is an"||" "||"%generate_string"||".";
put output=;
run;
You may be overcomplicating this. If you start as @novinosrin suggested:
%macro generate_string;
%let string = apple;
&string
%mend generate_string;
Now you can get the value of &STRING easily:
%let output = This is an %generate_string.
If you need the output as a character variable within a data set, you can similarly use:
data want;
set have;
output = "This is an %generate_string.";
run;
%macro generate_string;
apple
%mend generate_string;
data _null_;
output1 = 'This is an ' || "%generate_string" ||.;
put output1=;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.