BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mariko5797
Pyrite | Level 9

I am new to using PROC REPORT and do not fully understand how the sorting works. My code is as follows (substituted with dummy variables):

proc report data = working nowd split = '*'
 %reportStyle;

 column VAR TIME _STAT_ CAT1 CAT2 CAT3;

 define VAR / order 'Variable' order = data style(column) = [just = left cellwidth = 0.7in];
 define TIME / order 'Subvariable' order = data style(column) =...;
 define _STAT_ / display 'Statistics' format = stat. style(column) = ...;
 define CAT1 / display 'CAT1' ...;
 define CAT2 / display 'CAT2' ...;
 define CAT3 / display 'CAT3' ...;

 compute after;
  line "Footnote";
 endcomp;
run;

I want it to first sort by Subvariable and then by Variable, while maintaining my desired order of columns. 

 

mariko5797_4-1627501929750.png

mariko5797_2-1627501864555.png

 

Thank you in advance.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Introduce an extra copy of the second column as a hidden zero-th column to sort by.

proc report data=sashelp.class ;
  column sex=extra name sex age ;
  define extra / order noprint;
  define name / order ;
  define sex / order;
  define age / display;
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Introduce an extra copy of the second column as a hidden zero-th column to sort by.

proc report data=sashelp.class ;
  column sex=extra name sex age ;
  define extra / order noprint;
  define name / order ;
  define sex / order;
  define age / display;
run;
Cynthia_sas
SAS Super FREQ
Hi:
Without data, no one can run or tweak your code. When PROC REPORT does ordering, it orders the items from left to right (the same as PROC SORT). So when you list VAR first and then TIME, the result is that the report is ordered by TIME within VAR. If you want the order to be different you have to switch the order of VAR and TIME in the COLUMN statement so that TIME is first.
Cynthia

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2181 views
  • 1 like
  • 3 in conversation