BookmarkSubscribeRSS Feed
mick_g
Calcite | Level 5
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
4 REPLIES 4
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Mick_g,

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

Sincerely,
SPR
mick_g
Calcite | Level 5
Summary2 data

Date Total_Calls Total_LM
1/1/2011 10 5
1/2/2011 15 3
1/3/2011 10 3
.......
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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
DouglasMartin
Calcite | Level 5
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
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1622 views
  • 0 likes
  • 3 in conversation