Hello everyone,
What is wrong here?
%macro HELLO;
%global game;
%let game = 0;
run;
%mend HELLO;
%HELLO;
data out.TV (KEEP=STUDYID DOMAIN VISITNUM VISIT VISITDY ARMCD ARM TVSTRL TVENRL);
retain STUDYID DOMAIN VISITNUM;
set TV;
if &game. ne 0 then abort cancel;
if &game. ne 0 then
putlog'WARNING: A prior error has occurred or environment is not correctly initialised. WARNING: SDTME_TV_ALL_V01 terminated';
if &game. eq 0 then
%do;
/*And then the rest of the program follows*/
The task is to terminate the program without output if the global macro variable is not 0, and then write the warning in the log.
I hope you can help me. Iv'e never worked with global macro variable before, or tried to write something in the log.
Best regards,
Hello, @Ninna1,
@Kurt_Bremser is quite correct. You cannot have a %do inside of a Data step as part of the Data step logic. I would change your code as shown below.
Comments:
%macro HELLO;
%global game;
%let game = 0;
%mend HELLO;
%HELLO;
%MACRO Abort_Pgm;
%ABORT CANCEL;
%MEND;
%IF %BQUOTE(&Game) ^= 0 THEN
%DO;
%PUT WARNING: A prior error has occurred or environment is not correctly initialized. ;
%PUT WARNING: SDTME_TV_ALL_V01 terminated';
%Abort_Pgm;
%END;
data out.TV (KEEP=STUDYID DOMAIN VISITNUM VISIT VISITDY ARMCD ARM TVSTRL TVENRL);
retain STUDYID DOMAIN VISITNUM;
set TV;
/* the rest of the program follows*/
Regards,
Jim
You have a %DO in open code:
if &game. eq 0 then
%do;
Hello, @Ninna1,
@Kurt_Bremser is quite correct. You cannot have a %do inside of a Data step as part of the Data step logic. I would change your code as shown below.
Comments:
%macro HELLO;
%global game;
%let game = 0;
%mend HELLO;
%HELLO;
%MACRO Abort_Pgm;
%ABORT CANCEL;
%MEND;
%IF %BQUOTE(&Game) ^= 0 THEN
%DO;
%PUT WARNING: A prior error has occurred or environment is not correctly initialized. ;
%PUT WARNING: SDTME_TV_ALL_V01 terminated';
%Abort_Pgm;
%END;
data out.TV (KEEP=STUDYID DOMAIN VISITNUM VISIT VISITDY ARMCD ARM TVSTRL TVENRL);
retain STUDYID DOMAIN VISITNUM;
set TV;
/* the rest of the program follows*/
Regards,
Jim
You are welcome. Good luck with your program. 🙂
Jim
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.