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
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;
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!
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;
Thanks Reeza- that should work for this problem as the data is not large.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.