BookmarkSubscribeRSS Feed
Zhongda
Fluorite | Level 6

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:

PERMNOEVTDATERETDATEdays_to_previous_pdays_to_nextfirst_eventinter_eventprogram_codecounter_overallcorrect_overall
100288/17/990.0156258/17/99 19910211
100283/3/00-0.034483/3/00199232401222
100287/14/0607/14/06232430010231
100285/10/070.0045/10/07300 01242

 

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

 

 

1 REPLY 1
Zhongda
Fluorite | Level 6
Hi,
I found that this will work that is add one more line for if clause
as
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;
if counter_overall > program_code then counter_overall=1;

run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 133 views
  • 0 likes
  • 1 in conversation