Desktop productivity for business analysts and programmers

User defined formats

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

User defined formats

Hi.

I have a problem on creation user defined formats.

So, I try to create my own formats by using my dataset and want to add to the last row the "Not Found" values, but my code deletes the last rows and adds the "Not Found" statement. 

Please give me a hint. the code is below;

data control_format /view=control_format;
		
	set cuserv.ABC_General (drop=Quantity Retail_Price
                             rename=(N_Item_Name = Start
                                     Class = Label))
				            end = last;
		retain fmtname '$mdclass'
		       Type 'C';

			   if last then do;
			   Start = ' ';
			   HLO = 'O';
			   Label = 'Not Found';
			   end;
 
 run;


 proc format cntlin=control_format fmtlib;
 run;

Accepted Solutions
Solution
‎07-10-2017 06:40 AM
Super User
Posts: 5,369

Re: User-Defined Formats

If that's the only roadblock, it's easy to overcome.  Add an OUTPUT statement in two places:

 

data control_format /view=control_format;
		
	set cuserv.ABC_General (drop=Quantity Retail_Price
                             rename=(N_Item_Name = Start
                                     Class = Label))
				            end = last;
		retain fmtname '$mdclass'
		       Type 'C';
                           output;
			   if last then do;
			   Start = ' ';
			   HLO = 'O';
			   Label = 'Not Found';
output; end; run; proc format cntlin=control_format fmtlib; run;

View solution in original post


All Replies
Super User
Super User
Posts: 7,720

Re: User defined formats

You just need to control the output statement in the datastep (which is at the end by default):

data control_format;
  set cuserv.abc_general (drop=quantity retail_price rename=(n_item_name=start)) end=last;
  retain fmtname '$mdclass' type 'C';
  if last then do;
    output;
    start=' ';
    hlo='o';
    label='not found';
    output;
  end;
  else output;
run;
Contributor
Posts: 37

User-Defined Formats

Hi.

I have a problem on creation user defined formats.

So, I try to create my own formats by using my dataset and want to add to the last row the "Not Found" values, but my code deletes the last rows and adds the "Not Found" statement. 

Please give me a hint. the code is below;

data control_format /view=control_format;
		
	set cuserv.ABC_General (drop=Quantity Retail_Price
                             rename=(N_Item_Name = Start
                                     Class = Label))
				            end = last;
		retain fmtname '$mdclass'
		       Type 'C';

			   if last then do;
			   Start = ' ';
			   HLO = 'O';
			   Label = 'Not Found';
			   end;
 
 run;


 proc format cntlin=control_format fmtlib;
 run;
Solution
‎07-10-2017 06:40 AM
Super User
Posts: 5,369

Re: User-Defined Formats

If that's the only roadblock, it's easy to overcome.  Add an OUTPUT statement in two places:

 

data control_format /view=control_format;
		
	set cuserv.ABC_General (drop=Quantity Retail_Price
                             rename=(N_Item_Name = Start
                                     Class = Label))
				            end = last;
		retain fmtname '$mdclass'
		       Type 'C';
                           output;
			   if last then do;
			   Start = ' ';
			   HLO = 'O';
			   Label = 'Not Found';
output; end; run; proc format cntlin=control_format fmtlib; run;
☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 146 views
  • 2 likes
  • 3 in conversation