DATA Step, Macro, Functions and more

Why I have missed one format - when I am adding another category (or updating) my formats?

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

Why I have missed one format - when I am adding another category (or updating) my formats?

 

Hi Everyone,

 

Please go through the following codes and reply accordingly (I have stated my problem in it).

 

libname learn '/folders/myfolders/sas';

*-----------------------------------------------------------------------------------*
 Creating a test data set that will be used to make a CNTLIN data set
*-----------------------------------------------------------------------------------*;
data learn.codes;
	input ICD9 : $5. Description & $21.;
datalines;
020 Plague
022 Anthrax
390 Rheumatic fever
410 Myocardial infarction
493 Asthma
540 Appendicitis
;

*----------------------------------------------------------------------*
 Creating a CNTLIN data set from an existing SAS data set
*----------------------------------------------------------------------*;
data control;
	set learn.codes(rename= (ICD9 = Start Description = Label));
	retain Fmtname '$ICDFMT' Type 'C';
run;
title "Demonstrating an Input Control Data Set";
proc format cntlin=control fmtlib;
run;

*------------------------------------------------*
 Using the CNTLIN= created data set
*------------------------------------------------*;
data disease;
	input ICD9 : $5. @@;
datalines;
020 410 500 493
;
title "Listing of DISEASE";
proc print data=disease noobs;
	format ICD9 $ICDFMT.;
run;

*-----------------------------------------------------*
 Adding an OTHER category to your format
*-----------------------------------------------------*;
proc delete data=control;
data control;
	set learn.codes(rename= (ICD9 = Start Description = Label)) end = last;
	
	retain Fmtname '$ICDFMT' Type 'C';
	
	if last then do;
		Start = ' ';
		Hlo = 'o';
		Label = 'Not Found';
	end;
run;

/* 
Why from here (from last code) we have lost one (exactly last) format / Label viz. for code 540 Appendicitis?

It may be because of using if last then do; 

If it is so then please anyone give me an alternate way i.e. codes (simple & small if  possible) to achieve the same goal without missing last format

You can also see that this particular code 540 Appendicitis is missing for all remaining program.
*/


proc format cntlin=control fmtlib;
run; /* Note: Remember to run proc format again */

data disease;
	input ICD9 : $5. @@;
datalines;
020 410 500 493
;
title "Listing of DISEASE";
proc print data=disease noobs;
	format ICD9 $ICDFMT.;
run;


*--------------------------------------------------------------------------*
 Updating an existing format using a CNTLOUT=data set option 
*--------------------------------------------------------------------------*;

proc format cntlout=control_out;
	select $ICDFMT;
run;

data new_control;
	length Label $ 21;
	
	set control_out end=Last;
	output;

	if Last then
		do;
			Hlo=' ';
			
			Start='427.5';
			End=Start;
			Label='Cardiac Arrest';
			output;
			
			Start='466';
			End=Start;
			Label='Bronchitis';
			output;
		end;
run;

proc format cntlin=new_control;
	select $ICDFMT;
run;
Regards,
AG_Stats

Accepted Solutions
Solution
‎05-02-2016 01:13 PM
Super User
Super User
Posts: 6,499

Re: Why I have missed one format - when I am adding another category (or updating) my formats?

[ Edited ]

You overwrote the last value with blanks.  Add OUTPUT statements like in your last example.

 

data control;
  set learn.codes(rename= (ICD9 = Start Description = Label)) end = last;
  retain Fmtname '$ICDFMT' Type 'C';
  output ;	*<-- ADD ;
  if last then do;
    Start = ' ';
    Hlo = 'o';
    Label = 'Not Found';
    output; *<-- ADD ;
  end;
run;

 

View solution in original post


All Replies
Contributor
Posts: 65

Re: Why I have missed one format - when I am adding another category (or updating) my formats?

Also, please someone define what is HLO variable. Is its name and role is fixed? 

And, when and how we can use its High and Low (values/ options)?

Regards,
AG_Stats
Super User
Super User
Posts: 6,499

Re: Why I have missed one format - when I am adding another category (or updating) my formats?

Make some formats with different combinations of included upper and lower bounds and other categories and generate the CNTLOUT dataset and examine it carefully to see the patterns.

 

Or just read the manual.

 

HLO
specifies a character variable that contains range information about the format or informat. 
The following valid values can appear in any combination:
F specifies a standard SAS format or informat that is used with a value.
H specifies that a range's ending value is HIGH.
I specifies a numeric informat range.
J specifies justification for an informat.
L specifies that a range's starting value is LOW.
M specifies that the MULTILABEL option is in effect.
N specifies that the format or informat has no ranges, including no OTHER= range.
O specifies that the range is OTHER.
R specifies that the ROUND option is in effect.
S specifies that the NOTSORTED option is in effect.
U specifies that the UPCASE option for an informat be used.

 

Solution
‎05-02-2016 01:13 PM
Super User
Super User
Posts: 6,499

Re: Why I have missed one format - when I am adding another category (or updating) my formats?

[ Edited ]

You overwrote the last value with blanks.  Add OUTPUT statements like in your last example.

 

data control;
  set learn.codes(rename= (ICD9 = Start Description = Label)) end = last;
  retain Fmtname '$ICDFMT' Type 'C';
  output ;	*<-- ADD ;
  if last then do;
    Start = ' ';
    Hlo = 'o';
    Label = 'Not Found';
    output; *<-- ADD ;
  end;
run;

 

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 204 views
  • 4 likes
  • 2 in conversation