DATA Step, Macro, Functions and more

Replacing Text Strings Using Macro Variables

Reply
Contributor
Posts: 69

Replacing Text Strings Using Macro Variables

%let city = New Orleans;

title "Data for &city";

 

Why when i run these two statements, i still get "Data for &city" and not "Data for New Orleans" ?

thank you

Super User
Super User
Posts: 9,441

Re: Replacing Text Strings Using Macro Variables

You need to provide some information, I can tell nothing from that, and:

%let city = New Orleans;

title "Data for &city";

proc print data=sashelp.cars;
run;

Works fine for me.

Super User
Posts: 6,642

Re: Replacing Text Strings Using Macro Variables

That would happen if you actually used a slightly different set of statements:

 

%let city = New Orleans;

title 'Data for &city';

 

Single quotes need to be changed to double quotes, to permit macro variable values to resolve.

 

If that's not what happened, you'll need to post the log (including the step before these statements).  There are other, less likely, possibilities.

Contributor
Posts: 36

Re: Replacing Text Strings Using Macro Variables

Proc print;
%let city = New Orleans;

title "Data for" &city;
Run;
Trusted Advisor
Posts: 1,831

Re: Replacing Text Strings Using Macro Variables

[ Edited ]
Posted in reply to emrancaan

Move %LET staement before thr PROC PRINT line and move the &city inside the double quotes.

Ask a Question
Discussion stats
  • 4 replies
  • 114 views
  • 3 likes
  • 5 in conversation