0
votes

i looked at the answers for this topic which have very few character values to format into numerical values. i have more than 200 character values to format with their distinct id. and the distinct id with their character names are present in another sas dataset. so is there any other way to do it rather than writing the code like:

value  $county ' Carroll County'= 034
                   ' Chatham County'= 011
                   ' Fulton County'= 213
                   ' DeKalb County'= 002
.
.
.
                   ' Chattahoochee County'=510;                   ;
   run;

i'm using sas 9.3

1
I have done this regularly, but I have no working SAS computer at the moment, so I will not post an answer I cannot verify. You can create the format directly from the dataset, by using the PROC FORMAT with the CNTLIN= option. Actually I usually derived a temporary dataset from the original, because the PROC FORMAT expects to find the info it needs to build the format in certain variables, that never matched the original datasets I used. You can find some documentation here: support.sas.com/documentation/cdl/en/proc/65145/HTML/default/…Frazz

1 Answers

3
votes

Using the method recommended by Frazz, you would have something like this:

data mapping;
    set have1;
    fmtname = '$county';
    start = county_name;
    label = county_number;
    keep fmtname start label;
run;

proc format cntlin=mapping;
run;

Then you can apply the format using something like:

number = put(name, $county3.);

Keep in mind that you need the "start", "label", and "fmtname" variables for it to work. Also make sure you don't have duplicate county_names first, so that one county name maps to only one label.