From: Ya on 4 May 2010 11:45 On May 3, 6:46 pm, "nina" <s...(a)mailinator.com> wrote: > did not work correctly, see below, three(3) errors > > data xx; > input name $ value $; > cards; > A M*H > A GHH > B A?N > D J*N > D K?N > ; > > data xx1; > set xx; > retain fmtname '$mycode' type 'C'; > if index(value,'*') then do; > do s=65 to 65+25; > start=translate(value,byte(s),'*'); > label=name; > output; > end; > start=value; > label=name; > output; > end; > else do; > start=value; > label=name; > output; > end; > run; > > proc format cntlin=xx1; > run; > > data test; > input testvalue $; > name=put(testvalue,$mycode.); > cards; > MAH > MOH > ANN > KIN > K_N > ; > > data _null_;set ;put(_all_)(=);run; > > testvalue=MAH name=A > testvalue=MOH name=A > testvalue=ANN name=A (should be B) > testvalue=KIN name=K (should be D) > testvalue=K_N name=K (should be D) As Art showed in his revised code, the reason my code did not pick up some case is because in your original sample data, the wildcard is '?' only. If '*' is considered another wildcard, the code has to include it too.
From: Chris Jones on 5 May 2010 10:23 On 3 May, 18:33, "nina" <s...(a)mailinator.com> wrote: > a data dictionary defines a format value based on a wildcard > > example: > > name, value > A , M?H > A, GHH > B , ANN > C , K?N > > since the values that are defined with a "?" can be any character, what is a > good method for parsing out the matches in order to come up with the Name > value ? > > data test; > input testvalue $4.; > cards; > MAH > MOJ > MOH > ANU > ANN > KIN > K*N > ;;;; Why not use PROC SQL and the "like" function, replacing wildcards ? with _, and * with %
First
|
Prev
|
Pages: 1 2 Prev: Selecting cases(data step) for non sequential IDs Next: WHERE statement issue in data step |