DATA Step, Macro, Functions and more

Find out the countries which have highest and lowest Amount

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Find out the countries which have highest and lowest Amount

the below is the data set. and i need to compute the  countries which have highest and lowest Amount

so anyone can help me

and another question is to create a report to have Country wise Category based sum of Amount

Attachment

Accepted Solutions
Solution
‎09-06-2017 05:34 AM
Valued Guide
Posts: 558

Re: Find out the countries which have highest and lowest Amount

Posted in reply to Karan_Dumbre

First do a proc Means to get your totals into an output data set

 

proc means data=product sum;
	class country;
	var amount;
	output out=summary(where=(_type_=1)) sum=total;
run;

Then to get the maximum and minimum

 

proc sql;
	select country, total
	from summary
	having total=max(total) or total=min(total);
quit;

A simple report can be generated with Proc Print

 

proc print data=summary;
	var country total;
	title "Country Totals";
run;

Of course much more elaborate reports can be produced with SAS but as you give no further details I've just shown the simplest method :-)

View solution in original post


All Replies
PROC Star
Posts: 1,190

Re: Find out the countries which have highest and lowest Amount

Posted in reply to Karan_Dumbre

Without having opened your data, do something like this and adjust the class variables to your liking.

 

proc means data=product sum;
	class Country;
	var Amount;
run;
Occasional Contributor
Posts: 9

Re: Find out the countries which have highest and lowest Amount

i want which country has the highest amount n lowest amount

 i tried sorting the data set and display the first obs which is the lowest n last obs

Solution
‎09-06-2017 05:34 AM
Valued Guide
Posts: 558

Re: Find out the countries which have highest and lowest Amount

Posted in reply to Karan_Dumbre

First do a proc Means to get your totals into an output data set

 

proc means data=product sum;
	class country;
	var amount;
	output out=summary(where=(_type_=1)) sum=total;
run;

Then to get the maximum and minimum

 

proc sql;
	select country, total
	from summary
	having total=max(total) or total=min(total);
quit;

A simple report can be generated with Proc Print

 

proc print data=summary;
	var country total;
	title "Country Totals";
run;

Of course much more elaborate reports can be produced with SAS but as you give no further details I've just shown the simplest method :-)

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 171 views
  • 0 likes
  • 3 in conversation