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

 

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

Accepted Solutions
Tom
Super User Tom
Super User

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

3 REPLIES 3
AG_Stats
Quartz | Level 8

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
Tom
Super User Tom
Super User

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.

 

Tom
Super User Tom
Super User

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;

 

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