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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 2774 views
  • 0 likes
  • 2 in conversation