I am new to SAS so my question might be simple but i can not find anything on the internet to answer it so that is why I am asking it. I have some data that I am doing a proc sort on. In the data the information is organized randomly so I am doing my initial sort on the employee_id. Then i am using a proc print to sum the profits of individual employees based on their id. to this extent now i need the profit to be sorted by the total of their sales so highest profit generator to the top and in a descending manner. Can you help?
Thanks
Sounds like you have at least employee_id and some_profit_variable. Couldn't you just sort by:
by employee_id descending some_profit_variable;
Art, CEO, AnalystFinder.com
The profit is based on transactions so the proc print is generating the sum for each employee. At this step is when i would need to restructure the data generated to make the total profit from the individual transactions in a descending manner.
Do you need to print each individual sale, or do you need to print just the total of all sales per employee_id?
PROC PRINT is just a method to display data.
If you want to calculate sums then use PROC SUMMARY. With PROC SUMMARY you might be able to avoid the original sort and just use a CLASS statement instead of a BY statement.
proc summary data=have nway ;
class employee_id ;
var profit ;
output out=want sum= ;
run;
proc sort data=want ; by descending profit ; run;
proc print;
var profit employee_id;
run;
(or possible roll your own by writing a query using PROC SQL).
proc sql ;
create table want as
select employee_id,sum(profit) as profit
group by 1
order by 2 desc
;
quit;
You could also look at using PROC FREQ and trick it into make a sum by using your PROFIT variable as a WEIGHT variable. But watch out if you have negative or zero values for profit.
proc freq data=have order=freq ;
weight profit ;
tables employee_id;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.