BookmarkSubscribeRSS Feed
new_sas_user
Calcite | Level 5

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.

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

new_sas_user
Calcite | Level 5

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;

Source from: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000178212.htm#a000...

 

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).

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Your best bet is to read the manual - SAS documentation.  It has to do with the Program Data Vector:

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000961108.htm

 

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.

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 829 views
  • 0 likes
  • 2 in conversation