I create several formats by one control file. The variable a is a valid code in RF369 group and fact1 contains label RF369 which is expected. However, b is an invalid code in the RF390 code group and fact2 contains 'M8888' which is unexpected. How can I get blank in fact2, or a blank label if the code is invalid in any group?
data rfdata; input factor $ 1-7 stdcd $8-14; cards; RF369 E680 RF370 D780 RF370 D781 RF390 M66780 RF390 M781219 RF390 M123456 RF390 M231 ;; run; data cntrl; retain fmtname stdcd factor; set rfdata; length fmtname $10; fmtname='$'||strip(Factor)||'CD'; rename stdcd = start; rename factor= label; output; run; proc format library=work cntlin=cntrl; run; data usefmt; length a b $7 fact1 fact2 $20; a="E680"; b="M88888"; fact1=put(a, $RF369CD.); fact2=put(b, $RF390CD.); run;
Can you add an OTHER condition to mark those as blank or error?
In a PROC FORMAT it's
other = " "
Using a CNTLIN data set you use the HLO column instead and set that to O (letter o).
data cntrl;
retain fmtname stdcd factor;
set rfdata;
by factor;
length fmtname $10;
fmtname=strip(Factor)||'CD';
type='C';
rename stdcd = start factor= label;
output;
if last.factor then do;
hlo='O';
label=' ';
output;
call missing(hlo, label);
end;
run;
Can you add an OTHER condition to mark those as blank or error?
In a PROC FORMAT it's
other = " "
Using a CNTLIN data set you use the HLO column instead and set that to O (letter o).
data cntrl;
retain fmtname stdcd factor;
set rfdata;
by factor;
length fmtname $10;
fmtname=strip(Factor)||'CD';
type='C';
rename stdcd = start factor= label;
output;
if last.factor then do;
hlo='O';
label=' ';
output;
call missing(hlo, label);
end;
run;
With little modification (in the last.factor group, use factor instead of label), it works fine. Thank you very much.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.