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.

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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