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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.