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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
%macro generate_string;
%global string;
    %let string= apple;

  &string

%mend;

data _null_;
     output = "This is an"||" "||"%generate_string"||".";

    put output=;

run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
%macro generate_string;
%global string;
    %let string= apple;

  &string

%mend;

data _null_;
     output = "This is an"||" "||"%generate_string"||".";

    put output=;

run;
Astounding
PROC Star

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;

Satish_Parida
Lapis Lazuli | Level 10
%macro generate_string;
apple
%mend generate_string;

data _null_;
    output1 = 'This is an ' || "%generate_string" ||.;
    put output1=;
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
  • 3 replies
  • 595 views
  • 2 likes
  • 4 in conversation