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;
select sum(NUMBER*(TYPE='John' )) / ( sum(NUMBER) - sum(NUMBER*(TYPE='Sally' )) )
select sum(NUMBER*(TYPE='John' )) / ( sum(NUMBER) - sum(NUMBER*(TYPE='Sally' )) )
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.