BookmarkSubscribeRSS Feed
monday89
Fluorite | Level 6

Hi I have the following table:

groupeventFrequencyPercentCumulativeFrequency
afever220.002
acold330.005
acough110.006
aflu440.0010
bheadache220.002
bfatigue220.004
bfever110.005
bcold110.006

 

What I would like to do is that: take max cumulativefrequency of the "group" and create a static column. Something like this

 

groupeventFrequencyPercentCumulativeFrequencyTotal
afever220.00210
acold330.00510
acough110.00610
aflu440.001010
bheadache220.0026
bfatigue220.0046
bfever110.0056
bcold110.0066

 

i tried to proc sql;

create table test c as

select group, max(CumulativeFrequency) as total

from have;

group by group;

quit;

 

it works but i have to rejoin test and have. is there a way without creating additional dataset? 

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Try chaging your SELECT  clause to 

 

select *, max(CumulativeFrequency) as total

 

That will auto-remerge as long as the select clause has a variabe read from input table that is not part of a by group

 

 

unison
Lapis Lazuli | Level 10

Change:

proc sql;

create table test c as

select group, max(CumulativeFrequency) as total

from have;

group by group;

quit;

 

To:

 

proc sql;
create table test as
select *, max(CumulativeFrequency) as total
from have
group by group;
quit; 

 

-unison

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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