data have;
input Type $ State $ No;
datalines;
Failed AR 10
Failed AR 5
Passed MD 25
Failed MD 8
Passed MO 22
Passed MO 22
Failed NY 2
;
run;
Type | State | No |
Failed | AR | 10 |
Failed | AR | 5 |
Passed | MD | 25 |
Failed | MD | 8 |
Passed | MO | 22 |
Passed | MO | 22 |
Failed | NY | 2 |
desired results is | ||
Type | State | No |
Failed | AR | 15 |
Passed | MD | 25 |
Failed | MD | 8 |
Passed | MO | 44 |
Failed | NY | 2 |
TOTAL | Affected | 94 |
How can I get TOTAL in Type field, Affected in State field and the grand total at the end of No
If report, numerous pseudo codes for proc report and proc print are avaliable online.
If dataset, then
data have;
input Type $ State $ No;
datalines;
Failed AR 10
Failed AR 5
Passed MD 25
Failed MD 8
Passed MO 22
Passed MO 22
Failed NY 2
;
proc sql;
create table want as
select type,state, sum(no) as no_sum
from have
group by type,state
union
select 'total' as type,'affected' as state, sum(no) as no_sum
from have;
quit;
Looking to create a report or dataset output?
If report, numerous pseudo codes for proc report and proc print are avaliable online.
If dataset, then
data have;
input Type $ State $ No;
datalines;
Failed AR 10
Failed AR 5
Passed MD 25
Failed MD 8
Passed MO 22
Passed MO 22
Failed NY 2
;
proc sql;
create table want as
select type,state, sum(no) as no_sum
from have
group by type,state
union
select 'total' as type,'affected' as state, sum(no) as no_sum
from have;
quit;
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 25. 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.