DATA Step, Macro, Functions and more

Proc Computab

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Proc Computab

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


Accepted Solutions
Solution
‎09-27-2017 11:06 AM
Super User
Posts: 24,010

Re: Proc Computab

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


All Replies
Super User
Posts: 24,010

Re: Proc Computab

Computab is a new one to me....Smiley Happy 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?
New Contributor
Posts: 3

Re: Proc Computab

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!

Solution
‎09-27-2017 11:06 AM
Super User
Posts: 24,010

Re: Proc Computab

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;
New Contributor
Posts: 3

Re: Proc Computab

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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