Thank you so much Tom! I will try to do that!
Greetings!
Milenko
HI:
I would use PROC REPORT or PROC PRINT for a report like this. For example, using PROC REPORT, see a similar example using SASHELP.CLASS (where I add up the HEIGHT and WEIGHT instead of COUNT).
Cynthia
ods html file='c:\temp\Total_Line.html';
title 'Total Line for Students Heights';
proc report data=sashelp.class nowd
style(summary)=Header;
title 'Proc REPORT';
column name age sex height weight;
define name / order;
define age / order;
define sex / display;
define height/ sum;
define weight / sum;
rbreak after / summarize;
compute after ;
name='Total';
endcomp;
run;
ods _all_ close;
Cynthia! Thank you so much! But I dont need to do a report. I want to create another data set, and I will keep working with it, applying functions, etc.In any case, I really appreciate your help.!
Greetings!
Milenko
Hi,
data have;
data="data1"; c=2; output;
data="data2"; c=2; output;
data="data3"; c=1; output;
run;
proc sql;
create table WANT as
select *
from HAVE
union all
select "Total",
sum(C) as C
from HAVE;
quit;
One simple approach:
data y1;
input data $ count;
cards;
d1 100
d2 500
d3 800
d4 60
;
quit;
proc sql;
create table y2 as
select "total" as data, sum(count) as count
from y1;
quit;
data final;
set y1 y2;
run;
Hope this helps !!
Milenko,
This is in response to the question you asked . His code, with explanations, is shown below. The explanations are shown within comments, so that they don't have to be removed in order for the program to run:
data want;
set have end=last; /*use have to create new file called want and creating an extra temporary variable
called 'end' that will only have a value of 1 when the last record from have is read */
_ct+count; /*create a variable called _c1 that, by the time the last record is read, will contain the sum of
all values of count*/
output; /* output the record */
if last then do; /*ONLY do the following after the last record has been output */
var='Total'; /*Change the value of var to be Total*/
Count=_CT; /* Change the value of Count to equal the value of _CT */
output; /* Output the Total record */
end;
drop _ct; /* Drop _ct from the list of variables that will be output */
run;
Thanks, Art! And my apologize to OP. I haven't realized being asked a follow-up question until Art mentioned my name. The bottom line is that there is no way for me to do a better job than Art anyway , so OP, consider yourself lucky.
Arthur! Thank you so much! sorry for the late reply, but im not always working on SAS, your explanation was very helpful, although i dont completely understood it, but it worked perfect!
if instead of _ct+count ..i use _ct+sum ..or _ct+ any other function...would it work? What is the logic of using the operator + with a column?
and i dont understand very well what do you mean with "that will only have a value of 1 when the last record from have is read "
Anyway...you have been very helpful...I really appreciate !
Greetings,
Milenko
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.