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' )) )
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.