@jb9977 wrote:
Thanks for such a quick reply.. My values are in order and i have to define my priority. How can i do that ?
My values are IL, IN, SA, SP
SA priority 1
SP priority 2
IL priority 3
IN priority 4
Thanks,
Jay
I would use a custom format to create a new character value or an informat if I wanted a numeric:
proc format library=work;
value $priority
'SA'='1'
'SP'='2'
'IL'='3'
'IN'='4'
;
invalue priority
'SA'=1
'SP'=2
'IL'=3
'IN'=4
;
run;
data example;
input code $;
newchar = put(code,$priority.);
numval = input(code,priority.);
datalines;
SA
SP
IL
IN
;
run;
Formats and informats are one very slick reusable way to do lookups. And if you have a data set with the current value and the new value needed you can modify that to use as input to Proc format to make formats and informats.
And how to use with similar data to your previous example:
data have;
infile datalines truncover;
informat id best5. value $20.;
input id value ;
datalines;
1 SP,SA,SP
2 IL,IL,SP
3 IN,SP,IL
3 IN,IN,IL
;
run;
data want;
set have;
max_value= 99;
do i = 1 to (countw(value));
max_value = min(max_value,input(scan(value,i),priority.));
end;
drop i;
run;
A 99 would mean none of the coded values you have in your list of "priority" values was in the variable Value.
... View more