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

Hello all I have used to following code to add a row at the end of my data that totals the columns of data 

 

/*creating total row at bottom of data*/
proc means noprint data=c_&i.;

output out=summary_&i. sum=;

run;

data want_&i.;

set c_&i. summary_&i. (in=in2);

if in2 then program_description='Overall';

run;

 

The following article/question is where i found this solution: https://communities.sas.com/t5/SAS-Programming/Insert-a-Row-at-the-end-of-the-data-with-totals/td-p/...

 

The only issue I am having is that one of my columns is a date (in date 8 format) and i want to maintain this same date in the total "Overall" row. currently it is totaling the dates and providing that value. is there a way to do this? if so what would be the most efficient way? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc means noprint data=c_&i.;
    output out=summary_&i. sum= max(scoring_sample_date)=max_scoring_sample_date;
run;

data want_&i.;
    set c_&i. summary_&i. (in=in2);
    if in2 then do;
        program_description='Overall';
        scoring_sample_date=max_scoring_sample_date
    end;
    drop max_scoring_sample_date;
run;
--
Paige Miller

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

The only issue I am having is that one of my columns is a date (in date 8 format) and i want to maintain this same date in the total "Overall" row.


I don't really know what "maintain" means in this sentence.

--
Paige Miller
AustinHarris
Calcite | Level 5

for instance, in the picture below, I want the date to remain 01/03/202. As opposed to being a sum of the dates. 

 

AustinHarris_1-1673384805464.png

 

yabwon
Onyx | Level 15

Like this?

data have;
input a b ;
date = today() - _N_;
format date yymmdd10.;
cards;
1 4
1 5
1 6
2 5
2 9
2 10
;
run;

proc print data=have;
run;

proc means noprint data=have;
  output out=summary sum(a b)= max(date)=;
run;

data want;
set have summary (in=in2);
if in2 then program_description='Overall';
run;


proc print data=want;
run;

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



PaigeMiller
Diamond | Level 26
proc means noprint data=c_&i.;
    output out=summary_&i. sum= max(scoring_sample_date)=max_scoring_sample_date;
run;

data want_&i.;
    set c_&i. summary_&i. (in=in2);
    if in2 then do;
        program_description='Overall';
        scoring_sample_date=max_scoring_sample_date
    end;
    drop max_scoring_sample_date;
run;
--
Paige Miller
AustinHarris
Calcite | Level 5

I am receiving a syntax error.

 

AustinHarris_0-1673639181966.png

 

SASKiwi
PROC Star

Posting partial log screenshots isn't helpful as we can't see what has happened before. Please post your complete log using copy and paste and the </> icon, not a screenshot.

Reeza
Super User
It's missing a semicolon before the END statement.
Kurt_Bremser
Super User

Appending a "total" row to a dataset makes no sense. The dataset will become mostly unusable for further analysis, and reporting procedures can create such rows anyway.

Please post usable example data (in a data step with datalines), and the report you want to create from it.

Patrick
Opal | Level 21

@AustinHarris Short answer is: DON'T! 

It's a bad idea to add total rows to data (tables). That's what you're doing in reports and many of the SAS procedures creating such reports allow for creation of totals (=collapsing categorial data). Same is true for any VA reporting. You want all your source data in your table to be on the same detail level as else any coding will become harder.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 9 replies
  • 1473 views
  • 2 likes
  • 7 in conversation