Hello,
Here is a simplified example of what I trie to do :
data a;
input date sales;
datalines;
4 4000
;
data b;
input date value_purchased_items;
datalines;
1 100
2 200
3 300
;
proc sql;
create table summary as
select a.date, sum(b.value_purchased_items,0), a.sales
from a a, b b
where a.date=b.date;
I have no row with this request but I would like to have a row with "4 0 4000". How to deal with this? I tried coalesce by the same way and it did not work too.
Thanks
Hope this helps:
data a;
input date sales;
datalines;
4 4000
;
data b;
input date value_purchased_items;
datalines;
1 100
2 200
3 300
;
proc sql;
select a.date, sum(b.value_purchased_items,0) as sum_value_purchased_items, a.sales
from a left join b on
a.date=b.date;
quit;
Hello, not sure what you are trying to accomplish here. You are getting no rows because of the criteria you have specified in the where clause. There is no date common between the two tables.
Besides, you mentioned that you like to see 3 0 4000. you need to explain based on what criteria you expect this to be on your output so I understand.
Try "A LEFT JOIN B"
Hope this helps:
data a;
input date sales;
datalines;
4 4000
;
data b;
input date value_purchased_items;
datalines;
1 100
2 200
3 300
;
proc sql;
select a.date, sum(b.value_purchased_items,0) as sum_value_purchased_items, a.sales
from a left join b on
a.date=b.date;
quit;
Yes, provide and example of what you want out, and why.
Left join, I forgot this basic trick T_T
Thanks everyone for your help and your quickness!
A full join may be what you need. I would also anticipate the need to rollup by date both sales and purchases prior to joining.
data a; input date sales; datalines; 4 4000 5 8000 5 2000 ; data b; input date value_purchased_items; datalines; 1 100 2 200 3 300 3 600 5 125 5 250 5 500 5 1000 5 5000 ; proc sql; create table summary as select coalesce(a.date,b.date) as date , b.value_total , b.value_line_count , a.sales_total , a.sales_line_count from (select date, sum(b.value_purchased_items) as value_total, count(b.value_purchased_items) as value_line_count from b group by date) b full join (select date, sum(a.sales) as sales_total, count(a.sales) as sales_line_count from a group by date) a on a.date = b.date ;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.