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

Hi,

 

Have searched for a solution for my problem, but can't find it.

I'm using an SQL in a macro, and I want to resolve a macrovariable that needs to be between two single quotes in the WHERE clause:

 

 WHERE t2.CENTRUM = '&centrum'

 

when resolved, it should look like this:

 

 WHERE t2.CENTRUM = 'centre1'

 

Whatever I'm trying, I cant resolve &centrum when it's between the single quotes. Double quotes will resolve it, but I need the single quotes, otherwise my sql will not function.

 

What am I missing here?

 

 

Full code:

 

 

%macro create_list_per_centre;

%do c = 1 %to 5;

 %if &c = 1 %then %let centrum = centre1;
 %else %if &c = 2 %then %let centrum = centre2;
 %else %if &c = 3 %then %let centrum = centre3;
 %else %if &c = 4 %then %let centrum = centre4;
 %else %if &c = 5 %then %let centrum = centre5;

PROC SQL;

   CREATE TABLE WORK.&centrum AS
   SELECT t2.CENTRUM,
          t1.KEY,   
          (put(t2.YR,4.) || 'm' || strip(put(t2.periode2,2.))) AS PERIODE,
                  
      FROM WORK.error_ALL t1
           LEFT JOIN tableYYY t2 ON (t1.KEY = t2.KEY)
      WHERE t2.CENTRUM = '&centrum'
      ORDER BY t2.CENTRUM,
               t1.KEY,
               t1.error_type;
QUIT;


%end;

%mend;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Here is an example :

 

%let sex=F;

proc sql;
select *
 from sashelp.class
  where sex=%unquote(%bquote('&sex'));
quit;

View solution in original post

3 REPLIES 3
Ksharp
Super User

Here is an example :

 

%let sex=F;

proc sql;
select *
 from sashelp.class
  where sex=%unquote(%bquote('&sex'));
quit;
fre
Quartz | Level 8 fre
Quartz | Level 8

Thank you very much, it worked.

BrunoMueller
SAS Super FREQ

Hi

 

Please also have a look here https://communities.sas.com/docs/DOC-11204

 

There is a autocall macro %TSLIT that can be used and also an alternative macro provided by @Tom

 

Bruno

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3794 views
  • 1 like
  • 3 in conversation