07-15-2016 03:00 AM
I'm supposed to synthesize an explanation with multiple examples in which it DOES make a difference and multiple examples when it DOES NOT. Quite frankly, I don't really understand the question.
I understand the nature of the DATA step. I understand the uses of the DATA step, but I'm not understanding the question.
How would you interpret this question?
Thank you for your help.
07-15-2016 04:52 AM
Its quite simple. In some situations where a statement appears in a datastep makes no difference to the functionality, in other examples the order is very important. Here are two examples:
Order is not important:
data want; set have; ...do some code... format variable date9.; ...do some more code...; run;
In this example the format statement is only used once, and applied to the dataset, so it doesn't matter if it is at the beginning, the middle or the end of the code.
Order is important:
data want; set have; if variable=1; ...do some other code... run;
In this example, the position of the if can be critical, consider the case:
data want; set have; variable=1; if variable=1; run;
In the firs example, you will only get records where variable from the input dataset is 1, in the second example you will get all variables regardless of their value in the contributing dataset, as the if is executed after the assignment.
There are many times when this comes up, obviously conditional statements are the easiest to so as that changes the flow of the step, but other statements - position of a set statement for instance, declaration of variables after they are used etc. can affect the step.
07-15-2016 10:59 AM
Thank you very much, RW9.
Can you send me a link to a source where it would elaborate more on this? I have looked for FORMAT statements within DATA steps and I'm finding much more advanced examples, without enough of an explanation. Maybe I should be looking for a different keyword? Are you saying that because it is applying to the whole Dataset and not a subset, or a specific variable, the order is irrelevant? Here I found this:
Example 3: Removing a Format
This example disassociates an existing format from a variable in a SAS data set. The order of the FORMAT and the SET statements is important.
data rtest; set rtest; format x; run;
If they're stating that the order is important, then what would happen if the order was reversed?
RW9, do you have another example that you could elaborate on with regard to the BY statement in a DATA step. My understanding from here is that this could also be another example, but there are no examples on the support website (http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000202968.htm).
07-15-2016 12:28 PM
Your best bet is to read the manual - SAS documentation. It has to do with the Program Data Vector:
Think of it this way, if you try to format a variable which doesn't exist at that point...
Also note, that you can open SAS, and run the code and move that code line around to see what happens.