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!
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.
FILE is a reserved a key word, perhaps try using a differently name macro variable?
@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!
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.