BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MilenkoAndreas
Calcite | Level 5

Thank you so much Tom! I will try to do that!

Greetings!

Milenko

Cynthia_sas
SAS Super FREQ

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;

MilenkoAndreas
Calcite | Level 5

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

yeshwanth
Fluorite | Level 6

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 !!

art297
Opal | Level 21

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;

Haikuo
Onyx | Level 15

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.Smiley Happy

MilenkoAndreas
Calcite | Level 5

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 22 replies
  • 47121 views
  • 14 likes
  • 8 in conversation