SAS goto statement


/ Published in: SAS
Save to your folder(s)

You can use the goto statement to have SAS process statements in some other part of your program, by providing a label followed by a colon before the statements you wish to jump to. Label names follow the same rules as variable names, but have a different name space. When a labeled statement is encountered in normal processing, it is ignored.


Copy this code and paste it in your HTML
  1. /*Example*/
  2. data two;
  3. set one;
  4. if x ^= . then goto out;
  5. x = (y + z) / 2;
  6. out: if x > 20 then output;
  7. run;
  8.  
  9.  
  10. /*Example with data*/
  11. data class;
  12. input name $ 1-8 sex $ 11 age height weight;
  13. select (name);
  14. when ('Alice') do;
  15. goto Alice;
  16. end;
  17. when ('Becka') do;
  18. goto Becka;
  19. end;
  20. when ('Gail') do;
  21. goto Gail;
  22. end;
  23. end;
  24. Alice: x=4;
  25. return;
  26. Becka: x=5;
  27. return;
  28. Gail: x=6;
  29. return;
  30. datalines;
  31. Alice F 13 56.5 84.0
  32. Becka F 13 65.3 98.0
  33. Gail F 14 64.3 90.0
  34. run;

URL: http://jaredprins.squarespace.com/blog/2008/5/26/sas-flow-control-the-goto-statement.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.