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;
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;
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)?
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.