BookmarkSubscribeRSS Feed
dharmana01
Fluorite | Level 6

Hi,

 

I came across one dataset  which consist of

state region1 region2 region3

abc   20          30         50

def    40         30          30

ghi    25         35          40

xyz    30         45          20

i need to find out the sum of each region and which region is largest among the 3 regions?

Can some one help me ? 

 

 

 

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Use proc means 🙂

 

data have;
input state $ region1 region2 region3;
datalines;
abc 20 30 50
def 40 30 30
ghi 25 35 40
xyz 30 45 20
;

proc means data = have sum;
   var region1-region3;
run;
dharmana01
Fluorite | Level 6

Hi dray,

 

Thanks for your reply, but i am looking for result into new dataset with the variable state and only the region with larger .

will it can be done in data step itself? 

PeterClemmensen
Tourmaline | Level 20

So you want your variable state and the region variable which has the highest sum?

 

In the example posted, both region 2 and region 3 has sum equal to 140, then what? 🙂

dharmana01
Fluorite | Level 6

Hi dray,

 

Yes, i want the result with the variable state and the region variable which has the highest sum.

 

Apologies , observations was randomly given by me .And unfortunate region 2 and 3 sum become equal. you can change any one number either in region 2 and region 3.

 

Is this possible to do in the datastep itself?

 

AbhishekPr
Fluorite | Level 6
proc means data=DSN n min max sum;                                                                                                     
run;

You could generate summarization table for above dataset,

It would give you the sum of each region as well as largest among them

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 937 views
  • 2 likes
  • 3 in conversation