BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nnl3256
Obsidian | Level 7

 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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

2 REPLIES 2
Reeza
Super User

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;
nnl3256
Obsidian | Level 7

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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