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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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