We’re smarter together. Learn from this collection of community knowledge and add your expertise.

Top 10 SAS Functions

by SAS Employee megak8 on ‎08-28-2017 10:42 AM - edited a week ago (1,394 Views)

Recording: https://www.sas.com/en_us/webinars/top10-sas-functions/register.html


You don't need a dollar sign on the format when converting data to character with a PUT function?­

No, you don't. The format needs to match how the data is stored. PUT always writes character values­.


SUBSTR() works based on position, so it's useful if the strings are all the same location. If you knew the character was the last position of a string that could be 4, 5, or 6 characters long, how would you go about it?­

­You can use SUBSTR to read starting from the right and moving to the left.  ­


When deciding what length value to use when creating a copy of a column of a different data type, what is the best practice?­

­If the column you are creating is numeric, the storage will default to 8 bytes of floating point notation.  If you are creating character data, you should make the length long enough to accommodate the longest name.­


So if we want to have a "," between first and last name, we put newname=catx(",",fname,lname). Is that correct?­

If you want just the comma­ to be the separator, then yes, this syntax will work.­


­How/why was January 1, 1960 chosen?­ https://web.archive.org/web/20080706004217/http://support.sas.com/community/newsletters/news/insider...­



­Doesn't the informat in the input statement refer to the format of the character value and to display the new variable as a date you need a separate format statement. ­

The informat says how you want to read the value that is the first argument in INPUT.  The informat has to match how the data is stored. In this situation, we are creating a SAS date, which needs a format to be readable in output.­


How does SAS turn US dollars into other currencies? Because those conversions are always changing. https://communities.sas.com/t5/SAS-Enterprise-Guide/Currency-conversion-based-on-closest-exchange-ra...


Is there an online resource to look up functions and their syntax?




How do DATDIF and YRDIF handle leap years? And leap centuries?­

Leap years are accounted for within these (and other) functions – that’s one of their advantages.­


On transforming IDNO, we specify 4 digits, does that discard all values with 5 digits?



I always get INPUT and PUT confused and have to do trial and error to get the right one. Do you have some sort of hint i can use which can be used with numeric and character?­

­An easy way to remember is PUNCH as a mnemonic - PUT changes numeric to character. PUT always returns a character value; INPUT is the reverse - character to numeric­ - INPUT is the INverse of PUT. CHIN = character to numeric for input.


When can we use the SCAN function?­

The SCAN function can be used when we need to return a word from its relative position. For example, we might want word 1, word 2, etc. The words are delimited by default delimiters or the delimiters of our choice.


Can we think of FIND as a superset of INDEX (to be really quick)?­

Yes, you can think of the FIND function as a more powerful version of the INDEX function. Note that FIND allows us to specify a starting position – gives us more control. The FIND function and the INDEX function both search for substrings of characters in a character string; however, the INDEX function does not have the modifiers nor the starting position arguments as FIND provides.­



Can we create a custom for date formatting?­

Yes­. You can use the PICTURE statement in PROC FORMAT. Below are some examples:




There are a few places that the values appear to be reformatted, but it does not show up in the code.

Thanks for this constructive comment. We added formats for readability. We are revising the materials to better explain both the stored data value as well as a formatted value for purposes of readability.



How can we use ETL (Extract Transform Load) in SAS?­ I would like to know about the whole ETL process in SAS. Can you please provide some details about it?­

These kinds of functions - plus many others - conduct transformation work­. SAS offers many ETL tools and techniques https://www.sas.com/en_us/solutions/data-management.html­



How does the SCAN function work if there are multiple consecutive delimiters?­

Leading delimiters before the first word in the character string do not effect SCAN. If there are two or more contiguous delimiters, SCAN treats them as one. You can have any number of specified delimiters grouped together, and they are treated as one delimiter.


What is the second word in this as a SCAN statement­? ­given name = 'Stanley, the III' ­

The answer depends upon how you have specified your delimiters. If your delimiters are blank and comma, then the second word is ‘the’.


Will SAS date values export to Excel workbooks without modification (i.e. subtracting a constant) using 9.3 and above? 

If you have a SAS format associated with the date, you should be able to export the file to Excel without modifications. Please see the following:



Did she say that < > means that part of the function is optional?

Yes, <> indicates optional portions of the syntax.


Can I use these functions in SQL?­

Most SAS functions are available in the SAS implementation of SQL. Please see the following under the heading SAS DATA step functions for high level information about the types of functions supported 



by Trusted Advisor
on ‎08-29-2017 07:28 AM

Great collection of functions and demonstration of them in action! Thanks for sharing.


Interesting to see the usage question about INPUT and PUT functions. I wrote a SAS blog post a few years ago sharing how I remember this using mnemonics http://blogs.sas.com/content/sastraining/2013/02/26/rhymes-mnemonics-and-tips-in-learning-sas/

by Super User
on ‎08-29-2017 08:27 AM

The SCAN() function now supports the 'm' modifier to allow you to treat multiple adjacent delimiters as representing missing words. Like the DSD option on the INFILE statement.

Your turn
Sign In!

Want to write an article? Sign in with your profile.