01-09-2013 04:35 PM
As a new SAS user I am still figuring out the best way to find answers when I need to. I was hoping to gain suggestions from other users on how they search the documentation, forums or random corners of the web. I'll put forth an example of information I am currently seeking.
It is possible to 'or' multiple statements in an if statement in at least two ways. From what I can see, the following are functionally identical:
if country = 'CA' or country = 'US' then do;
if country in ('CA','US') then do;
The first example is fairly self explanatory. The use of parentheses is new to me and I have been trying to find more information on this. For example, it would be nice to know if there is a way to put conditions into a set of parentheses but yield an 'and' operator.
I've tried search the SAS documentation but it is pretty bad at bringing back relevant hits.
I've tried other Google searches, going so far as to exclude all SAS websites (-site:sas.com) and all pdfs (-filetypedf) to focus on blogs and forums but I haven't had luck.
I would like to know more about the parenthetic Or statement but more importantly - How do I find the answer myself!?!? I am sure it is available somewhere.
[Edit: At one point I found this searchable email archive. Are there other listserves commonly used for exchange among SAS users?]
01-09-2013 04:45 PM
Welcome to why the learning curve is so steep for SAS .. there is simply an awful lot there to learn.
You looked for the wrong thing. It isn't really an alternative us of or but, rather, an operator by itself. And, yes, there are even more ways in can be used such as with an array (which, surprisingly, doesn't require parentheses.
Take a look at: SAS(R) 9.2 Language Reference: Concepts, Second Edition
01-09-2013 05:07 PM
As Art says, there is a lot to learn. You may want to start with a basic "book by users" to get you over the hump. (Google <code site:sas.com> or <delwiche site:sas.com> for the author pages of two people who write clear introductory books.)
SAS is a language, so one of the keys to searching is to understand the 'parts of speech' to make your searches more precise. For instance, IF is a "statement", so searching
if statement site:sas.com
is quite useful for the general syntax. Similarly, "=" or "eq", and "|" or "or" are "operators", so searching
eq operator site:sas.com
gets you right to how to understand operators in expressions (An "expression" is the "part of speech" between the IF and the THEN parts of the statement.). "in" is a function.
These are all in the language reference that Art recommends. It's complete (and a bit overwhelming for a new user).
Update: IN is also an operator. (IN function is different and unsupported in SAS). Thanks, Art.
Message was edited by: Lawrence Muhlbaier
01-09-2013 04:56 PM
Ah, just wait until you discover that variable names are not restricted. This would be a perfectly legal SAS statement:
do do=to to to by by;
Good luck to all of us!
01-09-2013 06:19 PM
He could have been even nastier! Another thing that makes the learning curve even steeper is the fact that SAS will accept some misspellings.
The following will work, albeit with a couple of warnings:
sete sashelp.class (rename=(age=to weight=by));
doe do=to to to by by;
if do eq to the by=1;