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

I've tried restarting my SAS program and computer and this macro is just not running, no errors, nothing - just the code is in the log... I'm probably missing the simplest thing... am I calling in the macro variables correctly? I know sometimes you utilize a period so I thought that would be appropriate for the second macro variable.... Thanks for your help in advance!

 

%macro DX(no=, var=);

 

proc sql;
create table dx_&no as
select a.admission_id, b.DIAG_DESC
from adms_5 a left join table.DIAGNOSIS b on a.&var.=b.DIAG_CD;
quit;

 

%DX(no=1, var=DIAG_CD_1);
%DX(no=2, var=DIAG_CD_2_1);
%DX(no=3, var=DIAG_CD_2_4);

 

%mend DX;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@accintron wrote:

I've tried restarting my SAS program and computer and this macro is just not running, no errors, nothing - just the code is in the log... I'm probably missing the simplest thing... am I calling in the macro variables correctly? I know sometimes you utilize a period so I thought that would be appropriate for the second macro variable.... Thanks for your help in advance!

 

%macro DX(no=, var=);

 

proc sql;
create table dx_&no as
select a.admission_id, b.DIAG_DESC
from adms_5 a left join table.DIAGNOSIS b on a.&var.=b.DIAG_CD;
quit;

 

%DX(no=1, var=DIAG_CD_1);
%DX(no=2, var=DIAG_CD_2_1);
%DX(no=3, var=DIAG_CD_2_4);

 

%mend DX;


Try:

%macro DX(no=, var=);

proc sql;
create table dx_&no as
select a.admission_id, b.DIAG_DESC
from adms_5 a left join table.DIAGNOSIS b on a.&var.=b.DIAG_CD;
quit;

%mend DX; 

%DX(no=1, var=DIAG_CD_1);
%DX(no=2, var=DIAG_CD_2_1);
%DX(no=3, var=DIAG_CD_2_4);

 


Attempting to use the macro in the defining code is a path to madness and unexpected results.

I would also suggest shutting down SAS and restarting as you may have created an very unstable situation.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You defined the macro, you never told SAS to execute the macro after it has been defined.

 

These go after %MEND;

%DX(no=1, var=DIAG_CD_1)
%DX(no=2, var=DIAG_CD_2_1)
%DX(no=3, var=DIAG_CD_2_4)

 

 

--
Paige Miller
accintron
Obsidian | Level 7

Woops! Thanks!! Yes, that worked and I had to use . after my &no macro variable. 

ballardw
Super User

@accintron wrote:

I've tried restarting my SAS program and computer and this macro is just not running, no errors, nothing - just the code is in the log... I'm probably missing the simplest thing... am I calling in the macro variables correctly? I know sometimes you utilize a period so I thought that would be appropriate for the second macro variable.... Thanks for your help in advance!

 

%macro DX(no=, var=);

 

proc sql;
create table dx_&no as
select a.admission_id, b.DIAG_DESC
from adms_5 a left join table.DIAGNOSIS b on a.&var.=b.DIAG_CD;
quit;

 

%DX(no=1, var=DIAG_CD_1);
%DX(no=2, var=DIAG_CD_2_1);
%DX(no=3, var=DIAG_CD_2_4);

 

%mend DX;


Try:

%macro DX(no=, var=);

proc sql;
create table dx_&no as
select a.admission_id, b.DIAG_DESC
from adms_5 a left join table.DIAGNOSIS b on a.&var.=b.DIAG_CD;
quit;

%mend DX; 

%DX(no=1, var=DIAG_CD_1);
%DX(no=2, var=DIAG_CD_2_1);
%DX(no=3, var=DIAG_CD_2_4);

 


Attempting to use the macro in the defining code is a path to madness and unexpected results.

I would also suggest shutting down SAS and restarting as you may have created an very unstable situation.

accintron
Obsidian | Level 7

Thank you! Yes, definitely will restart SAS fresh now that the code is working appropriately!

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2813 views
  • 0 likes
  • 3 in conversation