BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bhavanaa44
Fluorite | Level 6
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.
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

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;
Kurt_Bremser
Super User

@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().

ballardw
Super User

I very much agree with @Kurt_Bremser.

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;
Bhavanaa44
Fluorite | Level 6
@PeterClemmensen

It worked well even I tried with adding more categories as well.
Thanks a lot
PeterClemmensen
Tourmaline | Level 20

@Bhavanaa44, glad to know that it worked. However, it is a much better solution to use formats, especially when you add more categories.

 

Regards.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1477 views
  • 4 likes
  • 4 in conversation