DATA Step, Macro, Functions and more

Use of IFC and IFN

Reply
Occasional Contributor
Posts: 6

Use of IFC and IFN

As IFC and IFN can be used in place of IF-THEN-ELSE
But how to create more than 2 codes such as mild, moderate, and Severe.

Do help me.
PROC Star
Posts: 1,400

Re: Use of IFC and IFN

Posted in reply to Bhavanaa44

While I generally dont like the approach, you can ise nested IFC Functions like this

 

data have;
   do value=0 to 100;
      output;
   end;
run;

data want;
   set have;
   severity=ifc(value ge 80, "Severe", ifc(value ge 20, "Moderate", "Mild"));
run;
Super User
Posts: 10,570

Re: Use of IFC and IFN

Posted in reply to Bhavanaa44

@Bhavanaa44 wrote:
As IFC and IFN can be used in place of IF-THEN-ELSE
But how to create more than 2 codes such as mild, moderate, and Severe.

Do help me.

Use a value format with ranges. All the conditions turn into a single put().

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 13,941

Re: Use of IFC and IFN

Posted in reply to KurtBremser

I very much agree with @KurtBremser.

If a category is based on a single variable then a custom format is a very superior way to handling for a number of reasons.

One of the most flexible elements of formats is the ability to use different formats with the same variable to create different groups for

analysis or reporting. Most of the modeling, analysis and graphing procedures will honor groups created by a format.

 

See below for an example. Notice that NO additional variables are created.

proc format library=work;
value mild_sev
0 - 20='Mild'
20<-80='Moderate'
80<-high='Severe'
;
value mild_vsev
0 - 20='Mild'
20<-40='Less Moderate'
40<-90='High Moderate'
90<-high='Very Severe'
;
run;

data have;
   do value=0 to 100;
      output;
   end;
run;
title 'Mild to servere format';
proc freq data=have;
   tables value;
   format value mild_sev.;
run;
title 'Mild to very severe format';
proc freq data=have;
   tables value;
   format value mild_vsev.;
run; title;
Ask a Question
Discussion stats
  • 3 replies
  • 57 views
  • 3 likes
  • 4 in conversation