DATA Step, Macro, Functions and more

create format with cntlin=

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

create format with cntlin=

[ Edited ]

 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;

 


Accepted Solutions
Solution
‎04-05-2018 12:00 PM
Super User
Posts: 23,958

Re: create format with cntlin=

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;

View solution in original post


All Replies
Solution
‎04-05-2018 12:00 PM
Super User
Posts: 23,958

Re: create format with cntlin=

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;
Contributor
Posts: 25

Re: create format with cntlin=

With little modification (in the last.factor group, use factor instead of label), it works fine.  Thank you very much.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 130 views
  • 1 like
  • 2 in conversation