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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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