Hi ALL,
I ma trying to count the varible in the group call counter_overall, but my code does not work for this special case below:
here is the dataset:
PERMNO | EVTDATE | RET | DATE | days_to_previous_p | days_to_next | first_event | inter_event | program_code | counter_overall | correct_overall |
10028 | 8/17/99 | 0.015625 | 8/17/99 | 199 | 1 | 0 | 2 | 1 | 1 | |
10028 | 3/3/00 | -0.03448 | 3/3/00 | 199 | 2324 | 0 | 1 | 2 | 2 | 2 |
10028 | 7/14/06 | 0 | 7/14/06 | 2324 | 300 | 1 | 0 | 2 | 3 | 1 |
10028 | 5/10/07 | 0.004 | 5/10/07 | 300 | 0 | 1 | 2 | 4 | 2 |
the counter_overall is the target I want but the numbers are wrong and the next column correct_overall is the right numbers
basically, if you take a look at the varible : program_code, for this case, it is 2,2,2,2. 2 means two event in a program and then with this program, the program_code is 2,2 and
2,2,2,2 here means, for permno 10028, there are two successive "two event program", my target is to number the sequence of the event in these two events groups.
so there is an invisible condition that is the counter_overall can not access the number of program code. Sorry I know it is quite confused , but let me explain it in another case:
suppose there is another stock permno 10000, and it has two successive three-event programs.
so the program code for this 6 obs is 3,3,3 , 3,3,3
and I would like to number the sequence as 1,2,3 1,2,3 instead of 1,2,3,4,5,6.
here is my code but it does not work FYI:
proc sort data = event_program;
by permno program_code;
run;
data event_program_more;
set event_program;
by permno program_code ;
retain counter_overall;
if first.program_code then counter_overall=1;
else counter_overall = counter_overall+1;
run;
Again, thanks a lot for the help.
Zhongda
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.