1 / 11

Lab 4 Wednesday, February 05, 2003

Lab 4 Wednesday, February 05, 2003. Manipulating Your Data with Boolean Logic and Iteration. Looping. Asking SAS to do something until a desired result is achieved.

yitta
Télécharger la présentation

Lab 4 Wednesday, February 05, 2003

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab 4Wednesday, February 05, 2003 Manipulating Your Data with Boolean Logic and Iteration

  2. Looping • Asking SAS to do something until a desired result is achieved. • “Rinse each dish, check to make sure it is clean. If it is, put it in the dishwasher; if not, repeat step 1. Stop when there are no dishes in the sink.”

  3. IF test • Used to specify when a command should be used. • IF there are no dishes in the sink, don’t wash dishes. Go do the next item on your to-do list. • SAS format: IF <condition>; instruction; IF X < 20 THEN Y = 1; (Young people in group 1)

  4. IF then DO • The IF loop can only perform one task. If you need to ask SAS to do several things if a condition is met, use a “IF then DO” statement. IF <condition> THEN DO; <task 1>; <task 2>; END;

  5. IF X < 20 THEN DO; • Y = 1; • A = SQRT(B) + 4; • END;

  6. WHILE loop • Performs a given task as long as the condition is true. • E.g.: While there are dishes in the sink; wash dishes. WHILE <condition> DO; <task1>; <task2>; END;

  7. WHILE (_N_ LT 10) DO; • SUM=X1+X2+X3; • AVE = SUM/3; • END;

  8. OUTPUT statement • Used within a loop to tell SAS to write that observation or case. • E.g.: “If that apple is good, store it; otherwise dump it. ” Output can also be used to write multiple observations from each input observation. IF <condition>; OUTPUT;

  9. DROP statement • Used to drop VARIABLES (not cases) from the dataset. • Can be used to clean up datasets after adding “flags”, or to include only interesting variables for analysis. DROP age gender IQ;

  10. Incrementing • Sometimes you want a set of instructions to be executed a certain number of times. • We use counter variables to keep track of the number of times an instruction set has been run. IF counter < 10 THEN DO; OUTPUT; counter = counter +1; END;

  11. Retaining Variables • By default, SAS resets each variable when it reads another case. This really messes up our counter variables, so to prevent it we tell SAS to “retain” the value of these variables from case to case. • We can set the initial value of these variables in the same statement. (default is 0 ) RETAIN counter counter2 0 index 1;

More Related