DATA Step, Macro, Functions and more

calculations

Reply
Contributor
Posts: 37

calculations

the code below is not adding the var nor is it outputing the last line; what am i missing
Data test_me (keep = Date Total_Calls Total_LM);
set Summary2 ;
retain var1 var2;
var1 = 0;
var2 = 0;

if not eof then do;
var1 = Total_ER_Calls + var1;
var2 = var2 + Total_ER_To_LM;
end;

if last._Date then do;
Date= "Grand Total";
Total_Calls = var1;
Total_LM = var2;
end;

run;

would like it to look like this;

Date Total_Calls Total_LM
1/1/2011 10 5
1/2/2011 15 3
grand total 25 8
Super Contributor
Super Contributor
Posts: 365

Re: calculations

Hello Mick_g,

Please provide a sample of your SAMMARY2 dataset to help you.

Sincerely,
SPR
Contributor
Posts: 37

Re: calculations

Summary2 data

Date Total_Calls Total_LM
1/1/2011 10 5
1/2/2011 15 3
1/3/2011 10 3
.......
Super Contributor
Super Contributor
Posts: 365

Re: calculations

This is a solution in the form you requested:
[pre]
data i;
length date $20.;
input Date $ Total_Calls Total_LM;
datalines;
1/1/2011 10 5
1/2/2011 15 3
1/3/2011 10 3
run;
data r (drop=tc tl) re(drop=Total_Calls Total_LM);
set i end=i;
tc+Total_Calls;
tl+Total_LM;
if i then output re;
output r;
run;
data r;
set r re (in=e rename=(tc=Total_Calls tl=Total_LM));
if e then date="Grand Total";
run;
[/pre]
I would like to note that you need a report. For this purpose it is better to use proc TABULATE or proc REPORT.
SPR
Contributor
Posts: 35

Re: calculations

mick_g - your problem is that you haven't set the eof variable anywhere, so your
if not eof then do...
block never executes.

You need to add end=eof to your set statement
Ask a Question
Discussion stats
  • 4 replies
  • 175 views
  • 0 likes
  • 3 in conversation