Say ahead, I do realized the following:
sas will still go throught if/do/end block regradless of the ‘if 0 then’ condition, to create variable c and d.
the 'correct' way could be using %if/%do/%end instead, to avoid any NOTEs in log.
but i am not looking for answers like that.
data test;
a = '32JAN2024';
b = 1;
c = input(a,date9.);
d = input(b,date9.);
run;
The above code will produce two NOTEs in the sas log, one is 'Numeric been convted to Character' and the other one is 'Invalid argument to INPUT'.
If i enclose the definition of c and d in a if/do/end block like below, the 'Numeric been convted to Character' NOTE is still in the log, but the 'Invalid argument to INPUT' NOTE was not in log anymore.
data test;
a = '32JAN2024';
b = 1;
if 0 then do;
c = input(a,date9.);
d = input(b,date9.);
end;
run;
I am curious about how SAS process a if/do/end block in data step. It is different than code outside of if/do/end block, right?
What happens is that the conversion numeric to character is detected during the compilation of the data step, so you get that message even if the statement is never executed. The "invalid argument to input" problem is detected during the execution of the data step, so if the line is not executed, you will not get that message.
The variables C and D will be created in the compilation step, but nothing will be assigned to them if the assignment statements are inside the "if 0 then do" block (D will be missing in both cases, as "1" is not a string in DATE9 format).
If you want to avoid the messages in the log, then
What happens is that the conversion numeric to character is detected during the compilation of the data step, so you get that message even if the statement is never executed. The "invalid argument to input" problem is detected during the execution of the data step, so if the line is not executed, you will not get that message.
The variables C and D will be created in the compilation step, but nothing will be assigned to them if the assignment statements are inside the "if 0 then do" block (D will be missing in both cases, as "1" is not a string in DATE9 format).
If you want to avoid the messages in the log, then
I see, thank you for your reply! It does help clear things up and points me to the right direction for further reading.
Basically, it can be divided into two phases, The Compile phase and The Execution phase. Two phases does difference things but could both produce some NOTE printed in the SAS log.
Attached a reading below for anyone who's curious:
SAS® DATA Step – Compile, Execution, and the Program Data Vector
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.