BookmarkSubscribeRSS Feed
saslackey
Calcite | Level 5
this is my table

region price sales
1 23 45
1 34 456
1 233 3465
1 65 34
2 23 3545
2 67 5653
i need to create a new table with

region median(price) sum(sales)


can someone tell me how to do that?
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi:
Depending on whether you want a report or an output dataset, SAS procedures that could give you that type of information is PROC MEANS, PROC TABULATE or PROC REPORT.

cynthia
saslackey
Calcite | Level 5
no actually i am writing a proc sql which i need help with. let me show you a small piece of my code.
finally2 is the table name

proc SQL;
Create Table last
(
REGION NUM,
sum_sales DEC,
median_price DEC );
Quit;

proc sql;
insert into last
SELECT finally2.REGION,
SUM(finally2.sales) As Sum_sales,
______ as median_price
FROM finally2
Group by finally2.REGION;
quit;
run;
Cynthia_sas
SAS Super FREQ
It looks like a report with a summary line to me. I would be tempted to use PROC REPORT with an RBREAK statement. See related post and program example here:
http://support.sas.com/forums/thread.jspa?threadID=11006&tstart=0

cynthia
Reeza
Super User
MS SQL does not have a built in median function. Even if SAS was going to pass through the function somehow the data would have to come back to your computer /SAS server to be processed by SAS.

Other SQL servers may, I'm not familiar with them.

If you're using SAS you're much better off using a proc tabulate or proc report or Proc Means.

proc sort data=sashelp.prdsale; by region; run;

Proc means data=sashelp.prdsale noprint;
by region;
var actual;
output out=last median(actual)=median_price sum(actual)=sum_sales;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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