BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BennyUnit
New User | Level 1

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?

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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

  1. do not use numeric inputs to character functions
  2. if you have a variable that may or may not be valid input for the INPUT function, and you do not want messages when the input is not valid, you can use the "??" modifier, e.g.
    "D=input(<character variable>,?? date9.)"

 

View solution in original post

2 REPLIES 2
s_lassen
Meteorite | Level 14

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

  1. do not use numeric inputs to character functions
  2. if you have a variable that may or may not be valid input for the INPUT function, and you do not want messages when the input is not valid, you can use the "??" modifier, e.g.
    "D=input(<character variable>,?? date9.)"

 

BennyUnit
New User | Level 1

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 119 views
  • 1 like
  • 2 in conversation