BookmarkSubscribeRSS Feed
Deanna_Payne
Obsidian | Level 7

I know there must be a way to loop through a datastep using 1 variable with multiple categories but I can't figure it out how. If someone could help me out that would be great.

 

I want to repeat the data step below using all of the different categories within the variable "Priority"

The control should stay priority = 2

But I want the case persons to loop through the other categories = 1, 3, 4, 5 so that I get 4 different Odds Ratios

 

proc format;

VALUE CC
1 = "CONTROL"
2 = "CASE"
3 = "EXPOSURE+"
4 = "EXPOSURE-";

run;

%LET EXPOSURE = NRT ;


DATA want;
SET have;

/* CONTROL PERSON = WHITE FORMER SMOKER*/
IF PRIORITY = 2 AND SMOKE=4 THEN CCGROUP = 1;
/* CASE PERSON = INDV PRIORITY GROUP + CURRENT SMOKER*/
IF PRIORITY = 5 AND SMOKE=5 THEN CCGROUP = 2;

/* EXPOSURE (+) YES USED NRT*/
IF &EXPOSURE = 1 THEN CCGROUP = 3;
/* EXPOSURE (-) DID NOT USE NRT */
IF &EXPOSURE = 2 THEN CCGROUP= 4;

FORMAT CCGROUP CC. ;
RUN;

 

PROC FREQ DATA= COMPARISONGROUPS ORDER=FREQ;
TABLES CCGROUP*EXP / OR;
RUN;

1 REPLY 1
Kurt_Bremser
Super User

Your code steps have no relation to each other; in one you create dataset want from dataset have, in the other you use dataset comparisongroups.

 

Please show us the code you really run to get a single result, and present the source data for this code in usable form (in a data step with datalines, so we can quickly and unambiguously recreate your example data).

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 603 views
  • 1 like
  • 2 in conversation