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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1499 views
  • 0 likes
  • 3 in conversation