<img alt="" src="https://secure.perk0mean.com/171547.png" style="display:none;">

Your SAS Secrets Exposed! [4 SAS Tips]


During my time in the life science industry I have learnt a lot of SAS techniques through attending training sessions, however some of the best SAS tips I have picked up were from other programmers: for instance when asking for advice on a coding problem or running programs written by colleagues. I found there are many simple SAS® tips you can use in your day to day SAS programming. This blog will provide explanations and examples of four of these.


The following four SAS® tips will be reviewed: 

  • Using the functions IFN and IFC as an alternative to IF THEN ELSE statements in conditional processing.
  • How to find out and use special characters which cannot be seen on your keyboard.
  • Making use of the ‘Where’ option in the data menu to find outliers and data issues.
  • Utilising the handy keyboard shortcuts available in PC SAS.



Most programmers will have used the IF THEN ELSE statements when working with conditional processing. Assigning one value for when the condition is true, and another value for when the condition is false. In these situations you can reduce lines of code by instead using the functions IFC and IFN.

These functions can both create a new variable with assigned values based on whether a condition is true or false. IFC will create a character variable and IFN will create a numeric variable.

Below are standard templates for using IF THEN ELSE to create numeric/character variables, along with their counterpart in IFN and IFC:

*Standard IF THEN ELSE code (numeric);

if condition then variable=value1;

else variable=value2;

 *Equivalent IFN code;


 *Standard IF THEN ELSE code (character);

if condition then variable='value1';

else variable='value2';

 *Equivalent IFC code;

variable=ifc(condition, 'value1' , 'value2') ;


You can see that IFN and IFC effectively cut down and rearrange the keywords from IF THEN ELSE code and change it into just one compact line of code.

For example both the following sets of code can be used to create the same variable:


if sex='Male' then sexcd=1;

else sexcd=0;




arrows table_1


Either code can be used here and will produce the same result. In order to compare processing times I ran equivalent code five times for each method and recorded the average times. These were run within server SAS version 9.1.3 and showed very little difference in average processing times. However the IFN function has the advantage of requiring less code.

These functions are ideal when you wish to create variables with 2 possible values.


There may be times when you need a specific character used in your outputs, for example superscripts or trade mark symbols in a footnote, but cannot see these directly on your keyboard. These characters and many more are all accessible for use in your SAS programs.

This table shows some of the special characters available to use, along with their corresponding byte number in SAS and a description.






Trademark sign



Copyright sign



Superscript a



Registered trademark sign



Degree symbol



Plus or minus sign



Superscript 2 / squared



Superscript 3 / cubed



Superscript 1



One quarter






Three quarters



Division sign



The full list of characters can be seen by running the following code. This will create a dataset with a variable containing each special character and a variable with each respective byte number in SAS.


data check;

  do i=1 to 255;






Once you know which character you want in your program, then you can use %let to create a macro variable of it. For example the following code will create a macro variable for the superscript a symbol:


%let supa=%sysfunc(byte(170));


If you want to check this has worked properly, then use %put to write the value of this macro variable to the log:

%put &supa;


The macro variable can then be inserted into your program. For example the following is standard proc report code for creating a table, but using this macro variable to create a superscript value in the footnote. The highlighted code shows where the macro variable is used.


proc report data=final nowd headline headskip split=' | ' ps=23 formchar(2)='_';

  column ('__' pdcdl col1 ord1 ord2);

  define pdcdl / left  '  ' width=60;

  define col1 / center 'DrugA|6 mg SC';

  define ord1 / order noprint;

  define ord2 / order noprint;

  title 'Table 14-1.3 Summary of Important Protocol Deviations';

  compute after _page_;

    line @13 72*"_";

    line @2 ' ';

    line @14 "&supa Other than Treatment Compliance/Test Article Administration";

    line @14 'Note: Deviation categories are not mutually exclusive';


  break after ord1 / skip;



This will create the following output. The highlighted part shows what the footnote looks like from inserting the special character into it.




As you can see in the example, it is a simple process to find out the byte number of the desired special character and then use it in your program.




Often in your datasets you may find issues, outliers and unexpected values, which sometimes may not be noticed straight away. There is a quick way to see all the unique values of a variable in a dataset by using the where option from the data menu.

Although its primary use is to subset the data, it is also ideal for getting an overview of what values a variable can take.

The following steps show an example of how to use this option:


1) Open a dataset and select 'Where...' from the 'Data' menu




2) Choose the variable you want to check




3) Select the EQ operator 



4) Select <LOOKUP distinct values>




5) List of values is now visible




Using this option will then show the unique values of that variable, sorted in ascending order. This makes for an easy way to get an overview of the data.

For example in your demographics dataset you could look at all the values of age. For a numeric variable like this, you will get to see the minimum and maximum values in the data and also get an idea of possible outliers.




Another example is looking at start dates in your adverse event dataset, as these can be subject to a lot of issues. Looking at this variable would let you see any incorrect / unusual values which will cause problems when programming.




Having this quick way of looking at data values can be great for saving time when wanting to check for issues, outliers and unexpected values.


When you are working on PC SAS there are many helpful keyboard shortcuts available at your disposal. For example when you need to comment or un-comment blocks of code, you can save time by using the shortcut instead of typing it all yourself. Or when you are trying to find the matching pair in a set of brackets, simply using the shortcut means that you will not need to spend the time searching yourself.

These actions can be performed with ease by pressing a few buttons on the keyboard. The following table shows some of the shortcuts available to use:



Keyboard Shortcut

Convert highlighted text to upper case

Ctrl Shift U

Convert highlighted text to lower case

Ctrl Shift L

Comment highlighted text

Ctrl /

Uncomment highlighted text

Ctrl Shift /

Collapse all sections of code

Ctrl Alt – (on number pad)

Expand all sections of code

Ctrl Alt + (on number pad) 

Move cursor to matching bracket

Ctrl (

Move cursor to matching DO or END statement

Alt [


The full list of available shortcuts can be accessed through the menu:
Tools -> Options -> Enhanced Editor Keys

This will show a list of all commands that have a keyboard shortcut assigned to them, along with a brief description of what the command will do.





Ticking the box Show all commands will then also show the commands that have not been assigned any shortcuts yet. These can then be set yourself if you want to use any. For example here are some of the unused commands which can be set a shortcut:

  • Convert highlighted text to opposite case
  • Insert current date and time
  • Delete line
  • Repeat the current line
  • Remove trailing white space from end of lines

The Assign keys… button can be used to set a shortcut or to change an existing shortcut.

Personally I find switching text to upper/lower case and commenting/un-commenting code to be especially useful and a good time saver.



These tips are all easy to learn, quick to use and great to share with other programmers. I would recommend trying these out to see if they can help you in your day to day SAS programming.

This content was originally written for PhUSE 2013 coders corners stream.


 Data Efficiency in Clinical Trials


Subscribe to the Blog