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

Hello , 

 

I have a SAS dataset that appear like this below and I am trying to sum the obs into a sum row inside the dataset.


Data DL_test;
input Count $ '2018q1'n '2018q2'n '2018q3'n '2018q4'n ;
datalines;
'C:1'n 1 2 3 4 5
'C:2'n 1 2 3 4 5
'C:3'n 1 2 3 4 5
'C:4'n 1 2 3 4 5
'C:5'n 1 2 3 4 5
'C:6'n 1 2 3 4 5
'C:7'n 1 2 3 4 5
;
run;

 

I have tried using the computab procedure, but can't seem to figure out why I'm getting Blank observations. 

 

proc computab data= DL_test notranspose out=DL_test_2 ;
rows 'C:1'n 'C:2'n 'C:3'n sum ;
Columns '2018q1'n '2018q2'n '2018q3'n '2018q4'n ;
RowBlk: Sum = Sum('C:1'n,'C:2'n,'C:3'n) ;
run;

 

Doesn't the "notranspose" option prevent the transpostion . It appears this is happening and that is why the data is all zeros. Is there another way to modify this or another procudre that could be used?

 

Thanks!

 

Mark

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Here's a manual way:

 

Data DL_test;
input Count $ Y2018q1 Y2018q2 Y2018q3 Y2018q4 ;
datalines;
'C:1'n 1 2 3 4 5
'C:2'n 1 2 3 4 5
'C:3'n 1 2 3 4 5
'C:4'n 1 2 3 4 5
'C:5'n 1 2 3 4 5
'C:6'n 1 2 3 4 5
'C:7'n 1 2 3 4 5
;
run;

proc means data=dl_test noprint;
var Y2018:;
output out=sum (drop = _:) sum=;
run;

data want;
set dl_test sum (in=b);
if b then count='Total';
run;

View solution in original post

4 REPLIES 4
Reeza
Super User
Computab is a new one to me....:) It depends on what you want. If you want a report - printed output to an ODS the PROC REPORT/PROC PRINT/PROC TABULATE are all options.  If not, and you want a data set, then PROC TABULATE is still an option, though a data step is more efficient.  Not 100% clear here, are you trying to sum the columns in each row or add a total column to the end of the report?
ICE1511
Calcite | Level 5

Hey Reeza,

 

I'm trying to sum the columns as to get

 

'C:1'n 1 2 3 4 5
'C:2'n 1 2 3 4 5
'C:3'n 1 2 3 4 5
'C:4'n 1 2 3 4 5
'C:5'n 1 2 3 4 5
'C:6'n 1 2 3 4 5
'C:7'n 1 2 3 4 5

SUM 7 14 21 28 35

 

and include this inside the dataset.

 

Thanks for the response!

Reeza
Super User

Here's a manual way:

 

Data DL_test;
input Count $ Y2018q1 Y2018q2 Y2018q3 Y2018q4 ;
datalines;
'C:1'n 1 2 3 4 5
'C:2'n 1 2 3 4 5
'C:3'n 1 2 3 4 5
'C:4'n 1 2 3 4 5
'C:5'n 1 2 3 4 5
'C:6'n 1 2 3 4 5
'C:7'n 1 2 3 4 5
;
run;

proc means data=dl_test noprint;
var Y2018:;
output out=sum (drop = _:) sum=;
run;

data want;
set dl_test sum (in=b);
if b then count='Total';
run;
ICE1511
Calcite | Level 5

Thanks Reeza- that should work for this problem as the data is not large.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1783 views
  • 0 likes
  • 2 in conversation