Trying the following code and it is not producing the results I expect. I am assuming it's because I'm using a defined variable in the sql in my group by statement?
data user.step_one;
length acct $10 strtdate $ 9 enddate $ 9 dsname $64;
input acct $ strtdate $ enddate $ size dsname $;
cards;
7733K772U1 01JUN2021 01JUN2021 100 KJDY01.TEST.ONE
7733K772U1 01JUN2021 01JUN2021 100 KJDY01.TEST.TWO
7733K772U1 01JUN2021 01JUN2021 100 KKSO01.TEST.ONE
7733K772U1 01JUN2021 01JUN2021 100 KJDY01.TEST.THREE
7733K772U1 01JUN2021 01JUN2021 100 KRRB01.TEST.ONE
7733K772U1 01JUN2021 01JUN2021 100 KRRB01.TEST.TWO
7733K772U1 01JUN2021 01JUN2021 100 KKSO01.TEST.TWO
7733K772U1 01JUN2021 01JUN2021 100 KRDO01.TEST.ONE
run;
proc sql;
select acct, strtdate, enddate, sum(size),
scan(dsname,1,'.') as hlq label='hlq'
from user.step_one
group by hlq, acct;
I expect just four lines of output with the summed size variable. I will try and run my summarization in another step and build the table with this code. Just curious.
You need to include strtdate and enddate in the GROUP BY clause, otherwise you get the automatic remerge (which is also NOTEd in the log - Maxim 2!)
You need to include strtdate and enddate in the GROUP BY clause, otherwise you get the automatic remerge (which is also NOTEd in the log - Maxim 2!)
Thank you sir. That does what I expect. I changed one of my acct numbers and further tested the group by and we are off and running. I'm not sure I quite understand that logic but looks like I have some reading to do. Thank you for referencing the efficient programmer link.
When youbdo GROUP BY in SQL, any item in the SELECT must either be
If a variable that is not part of GROUP BY appears in the SELECT, other SQL flavors will throw an error, but SAS will do an automatic remerge which results in all observations being kept, and put a corresponding NOTE in the log.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.