A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRConditional Logic in Macros

Introduction

  • Many clinical macros need to behave differently depending on the type of analysis β€” use means and standard deviations for continuous endpoints, counts and percentages for categorical ones.
  • SAS handles this with %IF / %THEN / %ELSE inside macro code. R uses standard if / else or switch() inside a function.
  • This lesson builds a macro/function that picks the right summary method based on a "type" parameter: continuous or categorical.
  • We use a small ADSL-like dataset and demonstrate both paths through the conditional logic.
  • After running, we confirm that the continuous path produces means and the categorical path produces frequency counts.

Conditional Logic in Macros