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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

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;
Astounding
PROC Star

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;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 1163 views
  • 2 likes
  • 3 in conversation