I have a variable Region (which is a number from 1 to 6). I have added a format like so:
[pre]PROC FORMAT library=PROJET.FORMATS;
1='Pacific' 2='Americas' 3='Oceania' 4='Middle East' 5='Asia' 6='Africa';
I want to sort them alphabetically (Africa, Americas, ... , Pacific) and not numerically by ID (Pacific, Americas, ... Africa). I have typed this:
[pre]proc sort data=TEMP; format Region $Region.; by Region; run;
proc sort data=TEMP; by Region; run;[/pre]
Ok to be more precise I actually simply need to output them sorted using the PROC MEANS method, so there is a statement/option in PROC MEANS that will allow me to sort it by formatted values (whilst keeping the dataset unchanged) then that will do fine.
Explore using the ORDER= parameter for PROC MEANS. Otherwise, to follow-on my reply and your subsequent question about a DATA step -- yes, exactly. If you are not interested in re-sequencing your data-values (another reply's suggestion), then you can use either a DATA step or a PROC SQL, along with the PUT function to create a new variable with the formatted value rather than the internal value of sort-ordering purpose.