From: nina on 3 May 2010 13:33 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 ;;;;
From: nina on 3 May 2010 13:47 any danger in using something like proc sql; create table match as select * from testvalue from testvalue x left join formatlookup b on x.testvalue LIKE b.value ;quit;
From: Ya on 3 May 2010 16:36 On May 3, 10:33 am, "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 > ;;;; You can construct your format based on the lookup dataset: data xx; input name $ value $; cards; A M*H A GHH B ANN C 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 ; proc print; run; Obs testvalue name 1 MAH A 2 MOH A 3 ANN B 4 KIN C 5 K*N C
From: nina on 3 May 2010 21:46 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)
From: Arthur Tabachneck on 4 May 2010 00:34 Nina, The following includes some lookups you may not want to include, but it does work for your example: data xx; input name $ value $; cards; A M*H A GHH B A?N D J*N D K?N ; data xx1 (drop=pos lookup); set xx; retain fmtname '$mycode' type 'C'; pos= index(value,'*') + index(value,'?'); if pos then do; lookup=substr(value,pos,1); do s=65 to 65+30; start=translate(value,byte(s),lookup); 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; HTH, Art ------------- On May 3, 9: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)
|
Next
|
Last
Pages: 1 2 Prev: Selecting cases(data step) for non sequential IDs Next: WHERE statement issue in data step |