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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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