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?
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;
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.
for instance, in the picture below, I want the date to remain 01/03/202. As opposed to being a sum of the dates.
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
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;
I am receiving a syntax error.
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.
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.
@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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.