BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
POOJA_J
Obsidian | Level 7

POOJA_J_0-1697457229593.png

POOJA_J_3-1697457454707.png

 

POOJA_J_2-1697457330267.png

Writing the above code, I expected the result to be grouped by my first variable name i.e bankid. But it's grouping on Marital status which is 2nd variable. Plz explain why its not getting grouped by bankid though it's written as 1st variable in group by!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Your ORDER BY statement groups the data by descending COUNT, that's what is happening. That's the order of the output data. If you want some other order, you need a different ORDER BY statement. The GROUP BY statement does not determine the order of the output data.

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Maybe you want a different ORDER BY statement?

--
Paige Miller
POOJA_J
Obsidian | Level 7

The code and the result generated in correct, it gives exact ans while solving MCQ's but I didn't understand the logic that even after writing bankid first in the GROUP BY statement, the table is getting grouped by marital status first and then within the marital status the bankid is getting grouped.

I was assuming the marital status to be grouped within the bankid.

There is my confusion. 

PaigeMiller
Diamond | Level 26

Your ORDER BY statement groups the data by descending COUNT, that's what is happening. That's the order of the output data. If you want some other order, you need a different ORDER BY statement. The GROUP BY statement does not determine the order of the output data.

--
Paige Miller
POOJA_J
Obsidian | Level 7
Great its solved now. Thanks for explaining.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1194 views
  • 1 like
  • 2 in conversation