Hi Everyone,
Here my concern is how to make a data-set mixture of Type = 'C' and Type = 'N' and use it as formats.
Below are the codes for Character formats and I want a dataset mixture of char and numeric formats.
Please modify the below dataset and codes accordingly. (If it is not possible with below program / codes then please give me some alternate program / codes for the same problem)
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;
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;
I'm not quite clear on your objective. Are you attempting to create numeric and character version of the same values? Or do you have a different range of numbers that want a different format?
If you are attempting to create a SINGLE Cntlin data set then when you create format statements you will need to sort the data by the format name before use in proc format.
Does this help?
data codes;
input ICD9 : $5. Description & $21.;
start = put (ICD9, z3.);
label = Description;
FmtName = '$ICDFMt';
type='C';
output;
FmtName = 'ICDFMt';
type='N';
output;
datalines;
020 Plague
022 Anthrax
390 Rheumatic fever
410 Myocardial infarction
493 Asthma
540 Appendicitis
;
run;
proc sort data=codes;
by FmtName start;
run;
Proc format library=work cntlin=codes;
run;
data test;
x=20;
y='022';
run;
proc print data=test;
format x Icdfmt. y $Icdfmt.;
run;
I'm not quite clear on your objective. Are you attempting to create numeric and character version of the same values? Or do you have a different range of numbers that want a different format?
If you are attempting to create a SINGLE Cntlin data set then when you create format statements you will need to sort the data by the format name before use in proc format.
Does this help?
data codes;
input ICD9 : $5. Description & $21.;
start = put (ICD9, z3.);
label = Description;
FmtName = '$ICDFMt';
type='C';
output;
FmtName = 'ICDFMt';
type='N';
output;
datalines;
020 Plague
022 Anthrax
390 Rheumatic fever
410 Myocardial infarction
493 Asthma
540 Appendicitis
;
run;
proc sort data=codes;
by FmtName start;
run;
Proc format library=work cntlin=codes;
run;
data test;
x=20;
y='022';
run;
proc print data=test;
format x Icdfmt. y $Icdfmt.;
run;
Thanks ballardw for your reply.
What codes should I use if I have a different range of numbers that want a different format. For this you can consider the following datalines:
/* Or you can consider any values / datalines as you like - that give me good exposure. */
datalines;
020 Plague
022 Anthrax
390 500.50
410 Myocardial infarction
493 200.50
540 Appendicitis
;
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.