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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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