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

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!

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.

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