Hello
I want to remerging summary statistics with raw data.
What is wrong here?
PROC SQL;
create table tbl as
select a.*,
(select sum(sales) as total_sales,
count(* ) as Total_count
from sashelp.shoes)
from sashelp.shoes as a
;
quit;
/*ERROR: A Composite expression (usually a subquery) is used incorrectly in an expression.*/
Why not simply
proc sql;
create table tbl as
select *,
sum(sales) as total_sales,
count(*) as Total_count
from sashelp.shoes;
quit;
Why not simply
proc sql;
create table tbl as
select *,
sum(sales) as total_sales,
count(*) as Total_count
from sashelp.shoes;
quit;
The answer you got from @PeterClemmensen is probably the solution I would suggest for this exact query. But there may be other situations where you want to use a subquery, you can do it like this:
PROC SQL;
create table tbl as
select detail.*,sum.*
from sashelp.shoes as detail,
(select sum(sales) as total_sales,
count(* ) as Total_count
from sashelp.shoes) as sum
;
quit;
Note that as your queries get larger and more complicated, it makes thing a lot easier in the long run if you use more describing aliases than "a" and "b", in this case "detail" and "sum" seem better. I know, everybody (except yours truly) use short and cryptic aliases, but they really should not!
Thank you so much!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.