I am attempting to do a column same sorted by two variables with proc sql but get the error message below:
proc sql;
create table sales as
select model, year
sum(revenue) as sum_revenue,
from carsales
_
22
76
Error 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &....
Error 76-322: Syntax error, statement will be ignored.
group by model, year;
run;
Have
model year revenue
acura 2013 15000
acura 2014 30000
acura 2014 150000
hyundai 2012 300000
hyundai 2012 300000
bmw 2007 1000000
bmw 2007 1000000
bmw 2007 1000000
Want
model year revenue sum_revenue
acura 2013 15000 15000
acura 2014 30000 180000
acura 2014 150000 180000
hyundai 2012 300000 600000
hyundai 2012 300000 600000
bmw 2007 1000000 3000000
bmw 2007 1000000 3000000
bmw 2007 1000000 3000000
Help?
You’re missing a comma after YEAR. And no commas before FROM.
You are missing a comma after year. You don't need the comma after sum_revenue.
proc sql ;
create table want as
select model,
year,
revenue,
sum(revenue) as sum_revenue
from carsales
group by model, year;
quit;
If find that you will lose track of where your commas are much less if you place them at the beginning of your continuation lines instead of at the end. It is much easier to scan the beginning of the lines of a block of code than the end of the lines.
proc sql;
create table sales as
select model
, year
, sum(revenue) as sum_revenue
from carsales
group by model, year
;
quit;
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.
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.