How does IF in SAS treat a missing value??

Every programming language has an IF-THEN statement that branches according to whether a Boolean expression is true or false. In SAS, the IF-THEN (or IF-THEN/ELSE) statement evaluates an expression and braches according to whether the expression is nonzero (true) or zero (false). The basic syntax is

if numeric-expression then
 do-computation;
 else
 do-alternative-computation;

One of the interesting features of the SAS language is that it is designed to handle missing values. This brings up the question: What happens if SAS encounters a missing value in an IF-THEN expression? Does the IF-THEN expression treat the missing value as “true” and execute the THEN statement, or does it treat the missing value as “false” and execute the alternative ELSE statement (if it exists)?

data A;
input x @@;
if x then Expr="True "; 
     else Expr="False";
datalines;
1 0 .
;

proc print noobs; 
run;

 temp2

Ah-ha! SAS interprets a missing value as “false.”

and also check the result for the below program:

data A;
input x @@;
if not x then Expr="True "; 
     else Expr="False";
datalines;
1 0 .
;

proc print noobs; 
run;

temp

Ah-ha! SAS interprets a missing value as “true.”  

More correctly, here is an excerpt from the SAS documentation:

SAS evaluates the expression in an IF-THEN statement to produce a result that is either non-zero, zero, or missing.
A non-zero and nonmissing result causes the expression to be true; a result of zero or missing causes the expression to be false.

If you do not want missing values to be treated as “false,” then do not reference a variable directly, but instead use a Boolean expression in the IF-THEN statement.

For example, in the following statement a missing value results in the THEN statement being executed, whereas all other numerical values continue to behave as expected.

 

DYNAMIC DATA EXCHANGE(DDE) in SAS

DYNAMIC DATA EXCHANGE(DDE) in SAS.

DYNAMIC DATA EXCHANGE(DDE) in SAS

DYNAMIC DATA EXCHANGE(DDE) in SAS.

DYNAMIC DATA EXCHANGE(DDE) in SAS

DDE: Dynamic data exchange alias DDE is a way for data transfer and exchange between Microsoft windows applications. SAS can utilize this functionality to transfer data to applications like MSexcel or MSword in a flexible and dynamic way.
DDE ADVANTAGES:
 
I know I know that right now you are saying that why in the world should I learn this new concept when I have PROC IMPORT and PROC EXPORT available, I even can use ODBC or just can import data using SAS EG.
Here is the answer…
When you are talking about proc import and proc export, these procedures are simple to use but provide less functionality to modify you data as DDE uses data step directly to transfer data. Secondly you should have an extra license SAS/ACCESS to use these procedures but DDE is just BASE SAS(windows).
ODBC also has same problem, an extra license.
SAS EG is a complete new SAS Client you have to buy and again the free thing is more flexible than this costly software so why not go for free, after all we love free stuff..!! J
DDE DISADVANTAGES:
 
Not keeping the debate one sided there are some disadvantages with DDE as well:
1) It works only in windows environment.
2) Application must be running on same computer from which SAS is exchanging data. Though we have a workaround for this, where we will start the application using SAS.
READING DATA USING SAS:
Here I will be discussing 3 ways to read data in SAS from MS Excel:
1) Getting data from clipboard:
This method is very simple, open Excel data, copy data using our favorite Ctrl-C which will send it to clipboard and then we can use SAS LIBNAME statement and DATA STEP to get that data.
First open an Excel file select the data you want to input as SAS dataset and press CTRL-C.
Then in SAS window write the following code:
filename bmi DDE ‘CLIPBOARD’;
data bmi;
  infile bmi missover;
  input ID SEX AGE EDUC CIG WEIGHT;
run;
So the dataset bmi is created with the observations copied to the clipboard. Pretty simple isn’t it..!!
Also now as you have the data step working with that data so run your imaginations wild and you can mould the data in any way before outputting it to the dataset.
2) Second technique is similar but it has a slight advantage over the previous technique that it does not require to copy data, but an extra step is also required, you need to find the DDE triplet which is of the form
Application|topic!item
But problem is how you will find the DDE triplet. It can be found out by copying the data from corresponding application then going into the Solutions menu -> Accessories -> DDE Triplet, this will give you the triplet.
Untitled
Now you will say this has not one step less but 2 steps extra. we had to copy data anyway and then go to solution menu and copy the triplet.
But this can be done once in a reusable code. And the triplet is self intuitive and you don’t need to copy it necessarily, you can type it yourself, I was just telling a way to get it with zero possibility of errors.
Now using the triplet you can write the following code to get your data:
filename bmi DDE ‘Excel|F:\SAS\sas datasets\[bmi1.xls]bmi1!R2C1:R10C6’;
data bmi;
  infile bmi missover;
  input ID SEX AGE EDUC CIG WEIGHT;
run;
Same as previous code just CLIPBOARD is replaced with the triplet.You can just change this triplet according to your needs.
NOTE: The application(Excel in this case) should be running when you are running this code.
3) Thirdly, we can just start the application in SAS itself so we are now free from the above requirement of application to be running.
The code goes something like:
OPTIONS NOXSYNC NOXWAIT;
X ‘”F:\SAS\sasdatasets\bmi1.xls”‘;
FILENAME bmi DDE ‘Excel|F:\SAS\sasdatasets\[bmi1.xls]bmi1!R2C1:R10C6’;
DATA sales;
  infile bmi missover;
  input ID SEX AGE EDUC CIG WEIGHT;
RUN;
The options NOXWAIT and NOXSYNC are mandatory and they tell SAS to not keep on waiting for user input after opening the application and return control.
The X tells SAS that what follows in single quotes is a windows command and just specifying the file path and name tells SAS to open it.
Rest is all same. You specify the DDE triplet and file is read into SAS dataset.
SO I have explained the 3 ways and all three are pretty simple and flexible so use them generously.
Further reading:
 
Below are a few interesting reads from the topic which will enhance your knowledge further.

 

FREQUENTLY ASKED SAS WRITTEN TEST/INTERVIEW QUESTIONS

FREQUENTLY ASKED SAS WRITTEN TEST/INTERVIEW QUESTIONS.

Differences between a merge and a join

Differences between a merge and a join.

Differences between a merge and a join

Below are the some differences between a merge and a join :
MERGE
JOIN
Default is one-to-one “outer-join” using the given order of observations in the source datasets
Default is Cartesian Product; joining all rows from one table with all the rows in the other table
Match-merge results by default in a special case of “full-outer-join”
Match-join results by default in an inner-join
Outer-joins may be done on multiple source datasets
Outer-joins can be done only on two source tables
Need to sort or index the source datasets before the data step match-merge
No need to sort or index the source tables before join
Requires variable or variables that are identical on all datasets
May join on columns which are named differently
In a one-to-one match-merge, common
variables that are not included in the
match condition (i.e. are not part of the
BY statement): the value from the latter
dataset sometimes overwrites the value
coming from the left-more dataset
Common columns are not overwritten unless
this is specifically managed by the code via
the use of the COALESCE function
Impossible to do a many-to-many merge
due to one-to-one behavior of MERGE
Relatively easy to do a many-to-many join
Fewer advantages when working with
tables stored in database servers since
databases are designed for extensive
matching tools
Most advantageous when working with tables
stored in Database Servers because
databases are designed for SQL processing
Usually more efficient when combining
small datasets but too much overhead on
large unsorted datasets!
More efficient than Merge when dealing with
multiple large datasets (or when combining an
indexed large table with a small table)