09-16-2013 05:51 AM
Suppose I have a format:
1='B' 2='A' 3='C';
Is there a way to automatically or easier way to reverse it?a
'B'=1 'A'=2 'C'=3;
Is there any simple way to convert (or reverse?) the informat to a format without having to hard code the second part? Something like put(input(.....))?
Why I need this?
I have some status in text and need to sort in priority by converting to numeric. After sorting by priority, I want to update the columns back to their text field.
09-16-2013 06:29 AM
One way is to export the format to a CNTLOUT table. Then rename START to LABEL and LABEL to START (and drop END) columns. You may also need to change the value of FMTNAME and TYPE.
And then just use the resulting table as a CNTLIN table to PROC FORMAT.
If you have overlapping target values in your current format, you need to figure out how to handle these in the "reverse" format.
09-16-2013 06:52 AM
It sounds like you want the NOTSORTED option on the value statement. That in conjunction with ORDER=DATA you may be able to achieve what you want with any extra work depending on you need..
For me I like to have a table to lookup the order when I need it. I do this by creating a data set of the formatted values along with an INDEX. Then I can use this data set to re-code the values when I get ready to have the order I want. In this example I use PROC SUMMARY to create the index variable using the LEVELS option. Then I, index the data set on the "variable" and the index variable. With this data I can lookup the index(sort order) or lookup the value based on the sort order, using a SET statement with the KEY=option. Or use the data to create an informat.
09-17-2013 11:00 AM
If you don`t want complex coding. and write that in simple. you should have to create new variable and apply format to that new variable and sort it. later in the final dataset just drop the new variable like below code..
input name $ value $;
value $inv 'A' = 1
'B' = 2
'C' = 3
'D' = 4
format new $inv.;
new = value;
proc sort data = test;
create table want as
select * from test(drop = new);
select * from want;
this code may help for your requirement..