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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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