Have you used a rhyme or spelling mnemonic to help you remember the spelling of a word? For me, the memorable, “i” before “e” except after “c” rhyme quickly comes to mind. Another memory tip I use is with the spelling of the word, stationery, as opposed to the word stationary. This tip came from my 3rd class teacher, Miss Cameron, where she explained that stationery with an “e” is for envelopes so from that moment on I knew the correct word to use, stationery versus stationary, in a sentence. And for those that have learnt to read music you may have learnt that the notes represented by the lines on the treble clef stave (bottom to top) as Every Good Boy Deserves Fruit (E, G, B, D, F) or some other variation. These are a few examples of rhymes and mnemonics I remember as a child and I am sure you can relate to these or others you have learnt over the years… Which got me thinking... Do SAS programmers use rhymes and mnemonics to remember SAS syntax?
In teaching the SAS Programming 2 for SAS Education Australia, there is a strategy/tip I put together for myself when I learnt SAS many years ago that I share with students and thought others might find it useful too. It relates to converting a SAS variable type; using the put and input functions. Unlike other programming languages where there is a numToChar and charToNum function (or similar function name), in SAS we use the put and input functions. The formal definitions of these functions are:
- put (source, format.) – returns a value using a specified format
- input (source, <? | ??>, informat.) - returns the value that is produced when SAS converts an expression using the specified informat.
These definitions can be a bit bewildering in trying to remember what function to use for the correct variable type conversion you are after. Some people may relate the input function being similar to the input statement where you read in character strings from an external file with the result being either a character or number (depending on the informat specified) however this strategy also relies knowing about the input statement.
The SAS Programming 2 course explains that the way to convert variable types is to use the put function for converting numeric variables to character (num ð char) and the input function for converting character variables to numeric (char ðnum). And with my tip below you may find it also a nifty way to remember this…
- put function - num to char (3 letters in the word put, 3 letters in num so the put function is for numeric to character variable conversion)
- input function - char to num (because the put function is for num to char then the input function is for character to numeric variable conversion)
A few years ago, an excited Programming 2 attendee (and obvious Seinfield fan) called out “That’s gold, Jerry! Gold!” as he had struggled to remember which function did what conversion and when I saw him recently he told me how this tip has helped him many times. As per the syntax definitions above, the input and put functions can be used for other conversions but I hope my tip can make it easy for you to remember in future which function to use to convert a numeric variable to a character variable (and vice versa).
I’m interested to know if this technique helps you and if you have any rhymes, mnemonics and tips that you use in learning SAS. Please share in the comments below or perhaps we can have a chat in person at SAS Global Forum in San Francisco in April. And check out this mnemonic from Charu Shankar for remembering the proper sequence of SQL statements.
12 Comments
I love mnemonics. I have my own little mnemonic for the conversion. Not the best one but it is fairly easy to remember. Its only for Char, but if you know what by exclusion you know the other.
CHARIN - Karen. Wordplay Kar-in in a Character. The in triggers input. By exclusion Num is Put. :)
I'm so relieved to hear that other longtime SAS users also struggle to remember the difference. As Tricia said, I use them both frequently and thought it would eventually sink in.
Of these suggestions, relating the functions to the statements works best for me. But as Michelle notes, these aren't helpful for beginner programmers.
IN PUT "u" sounds come at second place as in numeric its at second place so put means numneric to character and the other is oposite.
How about this pair of mnemonics as a starter for a way to remember what types of value each of the INPUT and PUT functions take and give ?
INPUT - Input Takes Character And Gives Both
Mnemonic: If Tom Can Add, Good Boy !
PUT - Put Takes Both And Gives Character
Mnemonic: People Taking Bribes Get Caught
I put these first attempts out here as a challenge to all to come up with something better.
Ideally, I would like the first word of each mnemonic to be the name of the function and even better for each mnemonic to be related in some way i.e. for each mnemonic to tell us something about Tom.
Any thoughts, anyone ?
Downunder Dave.
I like you trick to renumber these functions.
Shoot ... I gave up and put a sticky note on my monitor. I keep thinking that I do it often enough that I will remember ..... alas I never do. I need someone to INPUT some memory in my brain. :-)
I do the same thing...use cheat sheets on the yellow sticky notes. along with other hard-to-remember function syntax.
These are functions that actually seemed to make sense to me. Put also meaning to put your data into character form out in the log.... And so input must be the opposite.
Hi Gerald,
Thanks for sharing your thoughts. Yes I agree, for those that are familiar with the put statement, which writes out text to the log (or to a file if used with the file statement), they may easily remember what the put function does. This is the reverse to the example I gave above, where people may remember what the input function does, as they may relate it to the input statement, which outlines the specification of how to read characters from an external file.
Cheers,
Michelle
My colleague's mnemonic is that the letter "N" is second in the word "input", so that's how he remembers that the Numeric is the second thing (that is to say, what's returned as output) as opposed to the first thing (what's required as input). Of course, now I need a way to remember how to spell "mnemonic."
Thanks for sharing... Great to hear what other SAS users do.
"Please Eat My Dear Aunt Sally's Italian Lasagna" is a way to remember the order of precedence for matrix operators in the SAS/IML language.