DATA Step, Macro, Functions and more

proc freq how to change the order of yes no

Accepted Solution Solved
Reply
Super Contributor
Posts: 345
Accepted Solution

proc freq how to change the order of yes no

As we know, If you specify ORDER=DATA, the data are displayed in the same order as they occur in the input data set.  Other options for controlling order include ORDER=FORMATTED, which orders according to the formatted values, and ORDER=FREQUENCY, which orders by descending frequency count.

for me, my data is not what i expect, so the tables generate has "No" comes first beore "yes"

when i do copy and paste to the report, it is more time consuming

any advice how to change the order, so the "yes" always comes first before no, for each row, and column for each table?

Thanks.


Accepted Solutions
Solution
‎07-06-2016 03:22 PM
Trusted Advisor
Posts: 2,115

Re: proc freq how to change the order of yes no

One trick is to re-format the data.  You can put a space before the yes, so it is " yes" and leave the no as "no".  If th alignment causes you issues, you can use a non-printable character (you'll need to look at your collating sequence for that).

View solution in original post


All Replies
Contributor
Posts: 25

Re: proc freq how to change the order of yes no

Consider this code snippet

 

data report;
  set raw;
  if raw_value = 'Y' then display_value = 0;
  else display_value = 1;
  run;

proc format;
  value display
    0 = 'YES' 
   1 = 'NO';
    run;

proc report data = report missing;
  column <your-columns>;
  ...
  define display_value / order = internal format = display.;
 ...
  run;

 

Super Contributor
Posts: 345

Re: proc freq how to change the order of yes no

thank you, but i am using proc freq, and with sas macro

i do not now how to change your code to proc freq, since i have so many tables to generate

Solution
‎07-06-2016 03:22 PM
Trusted Advisor
Posts: 2,115

Re: proc freq how to change the order of yes no

One trick is to re-format the data.  You can put a space before the yes, so it is " yes" and leave the no as "no".  If th alignment causes you issues, you can use a non-printable character (you'll need to look at your collating sequence for that).

Contributor
Posts: 25

Re: proc freq how to change the order of yes no

Sorry about that. I'm a PROC REPORT guy.

 

Here is a snippet using PROC FREQ instead.

 

proc freq data = report;
  format display_value display.;
  table display_value /
     missing list order=internal;
run;
Super Contributor
Posts: 345

Re: proc freq how to change the order of yes no

thanks

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 535 views
  • 1 like
  • 3 in conversation