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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 5 replies
  • 1012 views
  • 4 likes
  • 4 in conversation