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.