Hi, I have a dose number counter variable (ORIGINAL DOSENUM) that, for some, does not start at "1" (ID 1). I want to reset this (or create a new counter variable) where all DOSENUMs start at "1" for each ID (as is the case for ID 2), i.e., DESIRED DOSENUM. Some original DOSENUMs start at 3, or 4 or 5, etc. I was able to create a new counter using , in the data step: "by ID ORIGINAL DOSENUM" followed by "if first.original dosenum then count+1", but this does not start the counter for each ID. Hope this is clear. Thanks.
data TEST1; input USUBJID $ EXSPID; cards; 01 3 01 3 01 3 01 3 01 4 01 4 01 4 01 4 01 5 01 5 01 5 01 5 02 1 02 1 02 1 02 1 02 2 02 2 02 2 02 2 02 3 02 3 02 3 02 3 ; run; Proc Sort data=test1; by USUBJID EXSPID; run; data test2; set test1; by USUBJID EXSPID; if first.exspid then count+1; Proc Print; run;
Hi,
Well, formatting your code so I can read it would help :smileyshocked:
You may be missing a retain:
data want;
set have; /* Assuming sorted! */
by id;
retain new_id;
if first.id then new_id=1;
else new_id=new_id+1;
run;
hey thanks (sorry 1st time user here):smileyblush:
yes, I was thinking I needed a retain somewhere
Your problem isn't that you're missing a retain statement, as using the sum function like you did automatically retains the variable. I think you need an extra if statement like:
data test2;
set test1;
by USUBJID EXSPID;
if first.USUBJID then count=1;
else if first.exspid then count+1;
run;
aha perfect, thank you!
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.