DATA Step, Macro, Functions and more

Understanding code

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

Understanding code

Hello Forum,

I the following code, "if  0 then" do?

Thanks.

data base;

if 0 then modify base;

set one two e04 open=defer;

output;

run;


Accepted Solutions
Solution
‎01-27-2015 05:04 PM
Super User
Posts: 11,343

Re: Understanding code

Posted in reply to kaushal2040

Suppose I am writing code per some directions from the boss and he says "We'll need to modify this table but the conditions wont' be set until the meeting next week." I know that I'll have to provide for handling that condition, which could be quite complex, but I don't know what it is at the time I start coding the pieces I do have requirements for. I put the stub of code you're asking about as a reminder of where in the process I need to implement that condition.

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Understanding code

Posted in reply to kaushal2040

0 is treated by SAS in logical comparisons as FALSE. So basically the code says not to do anything as the part following THEN only executes when the comparison is true.

This may be a programmer holding bit for testing other logic or does not know the conditions that will be needed but knows the conditional part will be needed later.

Contributor
Posts: 50

Re: Understanding code

Thanks ballardw,

So the code says do not modify the base data set?   I was wondering what " but knows the conditional part will be needed later'"  mean in your last sentence.

Solution
‎01-27-2015 05:04 PM
Super User
Posts: 11,343

Re: Understanding code

Posted in reply to kaushal2040

Suppose I am writing code per some directions from the boss and he says "We'll need to modify this table but the conditions wont' be set until the meeting next week." I know that I'll have to provide for handling that condition, which could be quite complex, but I don't know what it is at the time I start coding the pieces I do have requirements for. I put the stub of code you're asking about as a reminder of where in the process I need to implement that condition.

Super User
Super User
Posts: 7,080

Re: Understanding code

Posted in reply to kaushal2040

The program basically appends datasets ONE TWO and E04 to the end of the dataset BASE.

The "IF 0 THEN" does absolutely nothing in this case.  If you remove it and just have the MODIFY statement the code runs the same.

This construct is sometimes used with a SET statement instead of a MODIFY statement.  The effect then is that the compiler sees the SET statement and adds the variables in the referenced data set to the data vector but the IF 0 THEN causes the SET statement to never execute.  It is a quick way to make sure your new dataset has the same variables.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 204 views
  • 0 likes
  • 3 in conversation