BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Looking to create a report or dataset output?

novinosrin
Tourmaline | Level 20

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3262 views
  • 0 likes
  • 2 in conversation