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,

 

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

Accepted Solutions
ballardw
Super User

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;

View solution in original post

2 REPLIES 2
ballardw
Super User

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;
AG_Stats
Quartz | Level 8

Thanks 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
;

 

Regards,
AG_Stats

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 947 views
  • 1 like
  • 2 in conversation