BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ywon111
Quartz | Level 8

 

I have two datasets that I need to sum by type (eg John) then minus a specific type (eg Sally) from dataset one to calculate a % without specific type Sally. 

 

 

data one;
infile datalines delimiter=',';
input type $ number;
datalines;
John, 10
Peter, 22
Amy, 35
Sally, 34
;

 

data two;
infile datalines delimiter=',';
input type $ number;
datalines;
John, 1
Peter, 1
Amy, 2
Sally, 2
;

 

proc sql;
select
sum (John) as John1 label = "John" format=comma8.,
calculated John1/(select sum(number-sum(type='Sally')) from have2) label "John %" format=percent.

from have1;
quit;

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

select sum(NUMBER*(TYPE='John' )) / ( sum(NUMBER) - sum(NUMBER*(TYPE='Sally' )) )

View solution in original post

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

select sum(NUMBER*(TYPE='John' )) / ( sum(NUMBER) - sum(NUMBER*(TYPE='Sally' )) )

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1 reply
  • 2192 views
  • 1 like
  • 2 in conversation