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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.