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!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: