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

Hi All, 

I'm new to writing macros and have received the following error in my code. For reference, the macro ran correctly prior to me adding the dummy variable code. 

 

ERROR: Invalid macro name (. It should be a valid SAS identifier no longer than 32 characters.
ERROR: A dummy macro will be compiled.

 

 

/*CONTROL BY TIMEFRAME*/
%MACRO fin(file);

DATA work.&file._dm4;
SET work.&file._dm3;
IF (a1c_result<= 😎 THEN DM_control = 1;
IF (8< a1c_result <= 9) THEN DM_control = 2;
IF (a1c_result > 9) OR (a1c_result = .) THEN DM_control = 0;
run;
data work.&file._dm5;
set work.&file._dm4;
if dm_control=1 then well_cntrl=1; else well_cntrl=0;
if dm_control=2 then cntrl=1; else cntrl=0;
if dm_control=0 then uncntrl=1; else uncntrl=0;
RUN;

 

%MEND fin;

%fin(Baseline);
%fin(Q1_2019);
%fin(Q2_2019);
%fin(Q3_2019);
%fin(Q4_2019);
%fin(Q1_2020);
%fin(Q2_2020);

 

Thanks in advance for any clarifications or suggestions! 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

When I simplify your shown code to:

%MACRO fin(file);

DATA work.&file._dm4;
 set sashelp.class;
run;

%mend;

%fin(Baseline);

I have no problem:

265  %MACRO fin(file);
266
267  DATA work.&file._dm4;
268   set sashelp.class;
269  run;
270
271  %mend;
NOTE: The macro FIN completed compilation without errors.
      9 instructions 192 bytes.

272  %fin(Baseline);

NOTE: There were 19 observations read from the data set
      SASHELP.CLASS.

I suspect some other problem previously may be an issue with code thinking something other than what you show is the issue. You might try saving your code and restarting SAS. Some macro issues can be pretty persistent an this may be only the way to recover.

 

For future note, when asking about Error or other messages from the log, include the entire procedure or data step code prior to the messages along with all of the notes, warnings and or errors. Copy from the log and paste into a text box opened on the forum with the </> icon to preserve the formatting of the text and any diagnostic characters that SAS may have in the log.

View solution in original post

4 REPLIES 4
Reeza
Super User

FILE is a reserved a key word, perhaps try using a differently name macro variable?

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=mcrolref&docsetTarget=p0y...

 


@RebeccaB_ wrote:

Hi All, 

I'm new to writing macros and have received the following error in my code. For reference, the macro ran correctly prior to me adding the dummy variable code. 

 

ERROR: Invalid macro name (. It should be a valid SAS identifier no longer than 32 characters.
ERROR: A dummy macro will be compiled.

 

 

/*CONTROL BY TIMEFRAME*/
%MACRO fin(file);

DATA work.&file._dm4;
SET work.&file._dm3;
IF (a1c_result<= 😎 THEN DM_control = 1;
IF (8< a1c_result <= 9) THEN DM_control = 2;
IF (a1c_result > 9) OR (a1c_result = .) THEN DM_control = 0;
run;
data work.&file._dm5;
set work.&file._dm4;
if dm_control=1 then well_cntrl=1; else well_cntrl=0;
if dm_control=2 then cntrl=1; else cntrl=0;
if dm_control=0 then uncntrl=1; else uncntrl=0;
RUN;

 

%MEND fin;

%fin(Baseline);
%fin(Q1_2019);
%fin(Q2_2019);
%fin(Q3_2019);
%fin(Q4_2019);
%fin(Q1_2020);
%fin(Q2_2020);

 

Thanks in advance for any clarifications or suggestions! 


 

ballardw
Super User

When I simplify your shown code to:

%MACRO fin(file);

DATA work.&file._dm4;
 set sashelp.class;
run;

%mend;

%fin(Baseline);

I have no problem:

265  %MACRO fin(file);
266
267  DATA work.&file._dm4;
268   set sashelp.class;
269  run;
270
271  %mend;
NOTE: The macro FIN completed compilation without errors.
      9 instructions 192 bytes.

272  %fin(Baseline);

NOTE: There were 19 observations read from the data set
      SASHELP.CLASS.

I suspect some other problem previously may be an issue with code thinking something other than what you show is the issue. You might try saving your code and restarting SAS. Some macro issues can be pretty persistent an this may be only the way to recover.

 

For future note, when asking about Error or other messages from the log, include the entire procedure or data step code prior to the messages along with all of the notes, warnings and or errors. Copy from the log and paste into a text box opened on the forum with the </> icon to preserve the formatting of the text and any diagnostic characters that SAS may have in the log.

RebeccaB_
Obsidian | Level 7
Restarting SAS worked. Thank you!
Tom
Super User Tom
Super User

I do not see anything wrong with your code. Turn on MPRINT option and show relevant lines for the SAS LOG.  Make sure to use the Insert Code button (looks like < / >) to get a pop-up window to paste the lines of text so that the code is not converted into emojii like in your question.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 4 replies
  • 2241 views
  • 1 like
  • 4 in conversation