As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Tip of the Day:January 20

From sasCommunity
Jump to: navigation, search

sasCommunity Tip of the Day

data try ;
      none=0; meds=1; hosp=1;
      none=1; meds=0; hosp=0;
data _null_;
      set try;
      list = CatX(', ', IfC( none = 1 , 'NONE' , '' ),
                        IfC( meds = 1 , 'MEDS' , '' ),
                        IfC( hosp = 1 , 'HOSP' , '' ));
      put list= ;
run ;

Let's say you have a set of 0/1 dummy variables that are used to specify the treatments that a patient receives, and let's say that you want to put those treatments into a comma-separated list. This can be achieved using IFC within the arguments of CATX.

CATX trims leading a trailing blanks for the list of variables specified, and the first argument is the character(s) that you want to use to separate the values of the variables. Here we use a comma and a space. All of the variables in the TRY dataset have 0/1 values, so we use the IFC function. The first argument for IFC is some logical expression, the second argument is the value if true, the third is the value if false, and an optional fourth argument is the value if missing.

The LOG shows:


Special thanks to Toby Dunn for suggesting this technique.

Submitted By Otterm1

Feel free to comment on this tip.

Prior tip - Next tip - Random Tip

Submit a Tip