cancel
Showing results for 
Search instead for 
Did you mean: 

How i can do sorting from proc format by second column and not first like it does

alexmathp
Fluorite | Level 6

How i can do sorting from proc format by second column and not first like it does

Message contains an image

Hi to all,

 

I want to ask how we can do sorting from proc format by second column and not first like it does by default.

To make it clear what i mean, i want to my formats to be sorted by second column (the red circle) of the below picture

Capture.PNG

10 REPLIES 10
PeterClemmensen
Tourmaline | Level 20

Re: How i can do sorting from proc format by second column and not first like it does

I dont understand this. You want help to restructure the code or?

alexmathp
Fluorite | Level 6

Re: How i can do sorting from proc format by second column and not first like it does

when i load the formats in my data the sorting is from first column and not second like i want
Kurt_Bremser
Super User

Re: How i can do sorting from proc format by second column and not first like it does

Absolutely irrelevant. When the format is applied, later procedure steps will either order by formatted or unformatted values anyway, depending on the procedure.

If you want nicely ordered code, shuffle your code lines by selecting and moving.

PaigeMiller
Diamond | Level 26

Re: How i can do sorting from proc format by second column and not first like it does

Explain further. There is really no concept of sorting formats in SAS. Where should we see this proper sorting? In the output of some procedure? In a data set?

--
Paige Miller
alexmathp
Fluorite | Level 6

Re: How i can do sorting from proc format by second column and not first like it does

Yes i want to my data step to sort by the second column and not first like it does. Tell me if it clear now ok
Kurt_Bremser
Super User

Re: How i can do sorting from proc format by second column and not first like it does

The DATA step does not sort on its own. Certain procedures will order their output automatically.

If you want PROC SORT to sort by formatted values, you have to create a new variable containing the formatted values first.

In SQL, you can do that "on the fly":

proc format;
value mytest
  1 = "B"
  2 = "A"
;

data have;
input value;
format value mytest.;
datalines;
1
2
;

proc sql;
create table want as
  select put(value,mytest.) as value
  from have
  order by calculated value
;
quit;
PaigeMiller
Diamond | Level 26

Re: How i can do sorting from proc format by second column and not first like it does


@alexmathp wrote:
Yes i want to my data step to sort by the second column and not first like it does. Tell me if it clear now ok

You have not answered my questions: "Where should we see this proper sorting? In the output of some procedure? In a data set?"

--
Paige Miller
Tom
Super User
Super User

Re: How i can do sorting from proc format by second column and not first like it does

Message contains a hyperlink

Reordering the lines of the code used to generate the format will not have any effect on how the format is defined.

What is it that you really want to do?  

 

If you want something else to sort by the formatted values then store the formatted values into a another variable and sort by that.

If you are using PROC REPORT then use the ORDER=FORMATTED option. Note that is the default ordering for PROC REPORT.  https://support.sas.com/resources/papers/proceedings11/090-2011.pdf

 

alexmathp
Fluorite | Level 6

Re: How i can do sorting from proc format by second column and not first like it does

I want to make fac and bid file from the proc formats that i did already and the sorting to be done from the second column in some cases. If it is applicable of course?

ballardw
Super User

Re: How i can do sorting from proc format by second column and not first like it does

Please provide code by posting text in a code box.

I was going to show some affects of Formats and Procedure options but since you did not provide the code for the format as code I could execute I can't. I'm too lazy to retype someone else's work.

 

The PROCEDURE you use to display values will depend somewhat as to what you need to do get formatted values in a specific order (or not).

And since you have the formatted values '09' '07' and '08' appear more than once in the format it is not very clear what expected order you would expect.