Help using Base SAS procedures

I want know how can I make this procesure.

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

I want know how can I make this procesure.

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.


Accepted Solutions
Solution
‎03-23-2014 10:57 PM
SAS Super FREQ
Posts: 708

Re: I want know how can I make this procesure.

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


All Replies
Solution
‎03-23-2014 10:57 PM
SAS Super FREQ
Posts: 708

Re: I want know how can I make this procesure.

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;
New Contributor
Posts: 2

Re: I want know how can I make this procesure.

Posted in reply to Bruno_SAS

Thank you!!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 178 views
  • 0 likes
  • 2 in conversation