Help using Base SAS procedures

PRO SQL GROUP BY CLAUSE

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

PRO SQL GROUP BY CLAUSE

proc sql;
create table total2 as
select idnumber, jobcode, sale1, sale2, sum(sale1) as s1, sum(sale2) as s2,
           sum(sale1, sale2) as s3
 from sumy
 group by jobcode;
 quit;

Capture.PNG

 

Hello , is anybody can tell me about the order of observations in each group  without having clause and order by clause when group by clause?

In the attachment and code, the table total is the original data, after using groupy by clause, the entire data is grouped by jobcode shown in table total2. However, I found the order of observations in each group is werid. I assume the order should be sequencial as the original data, but is wasn't.

Order by clause can modify the order in each group, if there is no order by clause, what's the order convention in  each group, which is my concern.

Hope anyone can explain it for me.

Many thanks!

 

 

 


Accepted Solutions
Solution
2 weeks ago
Super User
Posts: 10,284

Re: PRO SQL GROUP BY CLAUSE

Posted in reply to Karen_sas11

It's undetermined, and an effect of the order in which observations are read from the utility file when the output is written.

Always specify the order yourself if you need a specific one.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
2 weeks ago
Super User
Posts: 10,284

Re: PRO SQL GROUP BY CLAUSE

Posted in reply to Karen_sas11

It's undetermined, and an effect of the order in which observations are read from the utility file when the output is written.

Always specify the order yourself if you need a specific one.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 4

Re: PRO SQL GROUP BY CLAUSE

Posted in reply to KurtBremser

Thank you Kurt, now I get it.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 124 views
  • 0 likes
  • 2 in conversation