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' )) )

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