Hi!
I'm working with data like the first table below where I have multiple records per id, some are positive some are negative (1 and 0, respectively). I also know whether there was a previous record, where the first instance is not 1, but each row for that id number afterward is. I want to get a count variable like the second table which cumulatively counts each record per id number.
I've tried some sql coding and a data step using the retain statement but can't get it quite right. Please help!
UNTESTED CODE
data want;
set have;
by id;
if first.id then count_record=0;
count_record+record;
run;
In the future, from now on (that's 100% of the time from now on) you need to post your data not as a screen capture, but as a SAS data step, by following these instructions and then people can provide you with TESTED code.
UNTESTED CODE
data want;
set have;
by id;
if first.id then count_record=0;
count_record+record;
run;
In the future, from now on (that's 100% of the time from now on) you need to post your data not as a screen capture, but as a SAS data step, by following these instructions and then people can provide you with TESTED code.
Perfect! Thank you. I'll ask questions per those instructions now.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.