I am a beginner to SAS. I am following the tutorials. I am confused on sorting and grouping.
proc print data= orion.sales; by country; run;
This code works well, and group the data set. When I run following code, it displays error.
proc sort data=orion.sales out=work.sort_sales; by salary ; run; proc print data=work.sort_sales; by country; Run;
I do not understand the reasoning behind having the same variable which we use to group by, in sorting statement.
SAS processess data line by line, so when you use a BY statement it expects the BY variables to be in order in the data. To ensure this is the case, you would first need to sort the data to have that specified order. So the BY variable list needs to be the same in your SORT and then your BY statements in further processes.
If you need a more detailed explanation, I suggest reading through the chapter on BY group processing in the documentation.
You sorted by salary, but tried to print by country. When sorting by salary, you destroyed the country sequence.
I do not understand the reasoning behind having the same variable which we use to group by, in sorting statement.
SAS processess data line by line, so when you use a BY statement it expects the BY variables to be in order in the data. To ensure this is the case, you would first need to sort the data to have that specified order. So the BY variable list needs to be the same in your SORT and then your BY statements in further processes.
If you need a more detailed explanation, I suggest reading through the chapter on BY group processing in the documentation.
Thank you so much for your quick reply. I will read the materials.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.