BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yubihan
Calcite | Level 5

There are three variables. company_code, year, count.

code year count      Sum_count

10    2000    1           1

10    2001    .             .

10    2002    1           1

10    2002    1           2

10    2003    1           1

10    2003    1           2

10    2003    1           3

20    2000    .            .

20    2000    1           1

I wnat know the code how can I make Sum_count variable.

Sum_count is the sum of count(by code, year).

If you help me I will really appreciate about it.

My english is not good. I'm sorry.

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

You can make use of BY group processing and the SUM statement. See sample below:

data have;
infile cards dlm=",";
input
  code :
$8.
  year :
4.
  count :
8.
  sum_count :
8.

;
cards;
10,2000,1,1
10,2001,.,.
10,2002,1,1
10,2002,1,2
10,2003,1,1
10,2003,1,2
10,2003,1,3
20,2000,.,.
20,2000,1,1
;

data want;
set have;
by code year;
if first.year = 1 then do;
  sumCount2 =
0;
end;

sumCount2 + count;

if missing(count) = 1 then do;
 
call missing(sumCount2);
end;
run;

View solution in original post

2 REPLIES 2
BrunoMueller
SAS Super FREQ

You can make use of BY group processing and the SUM statement. See sample below:

data have;
infile cards dlm=",";
input
  code :
$8.
  year :
4.
  count :
8.
  sum_count :
8.

;
cards;
10,2000,1,1
10,2001,.,.
10,2002,1,1
10,2002,1,2
10,2003,1,1
10,2003,1,2
10,2003,1,3
20,2000,.,.
20,2000,1,1
;

data want;
set have;
by code year;
if first.year = 1 then do;
  sumCount2 =
0;
end;

sumCount2 + count;

if missing(count) = 1 then do;
 
call missing(sumCount2);
end;
run;
yubihan
Calcite | Level 5

Thank you!!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 2 replies
  • 735 views
  • 0 likes
  • 2 in conversation