SAS SET

SAS Day3:

SAS SET statement is the most fundamental statement we use on a daily basis.
SET statement reads in all observations and variables from the assigned data set.

It never came across to me that the set statement could be used to solve advanced issues until I face the problem…..

Problem:
The pop dataset has 7 different dose level, we need to categorize the patients into 9 groups, in addition to the 7 different dose level, we need group 8 as the patients beyond max dose level (dose level 6,7), and group 9 for total patients.

Solution:
1. Set the original dataset pop twice, one for the 7 different dose level, one for the total patients, and set the max dose (dose level 6,7) patients from pop.
2. Assign a new variable, trtan, to capture the dose info from the original pop dataset. Assign the new variable, trtan, values for total and beyond the max treatment.
3*. Create a new id variable including patient ID and trtan info. (note: if we dont assign the new patient ID, there are potential duplication problems while counting)

Code:

data pop2;
set pop pop(in=a where=(maxdose=1)) pop(in=b);
if strtdose ne “” then trtan = input(scan(strtdose,1),3.);
if a then trtan=998;
if b then trtan=999;
length newid $ 25;
newid=strip(usubjid)||put(trtan,z3.);
run;

Alternative solution:

We can achieve the same result using OUTPUT, however, in this case, it might be a bit tedious.

Code :
data pop1;
set pop;
output;
strtdose=”ALL”;
output;
run;

data dosemtd;
set pop;
if strtdose in (“maxdose”) then do;
strtdose=”AT or above MTD”;
output;
end;
run;

data pop2;
set pop1 dosemtd;
run;

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade