Sunday, 6 July 2014

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:

Have you encountered places in SAS where missing values are handled in a surprising way? Please post your favorite example in the comments.
(courtesy: sasblogs)
a4
The best Training in Bangalore for SAS, SAS clinical, SAS projects, SAS Certification, Advanced Excel, VBA, and for .Net     is Signetsoft. 
A practical approach!

Real time expert faculty!!

Good in placement record!!!


contact us: info@signetsoft.com
mob: 9844559330


Monday, 10 March 2014

A quick tour of SAS operators

I want to understand the logic behind the answer to the following question:
The following DATA step is submitted:

data one;
 x=3;
 y=2;
 z=x**y;
 run;
What should be the value of the variable z in the output data set? Will you please explain what the ** symbol means, and how we solve the question?
-Too Many Asterisks
It is not intuitive that the ** symbol means exponentiation, as in X to the Yth power.  There are several arithmetic, comparison, and logical SAS operators (symbols), as well as miscellaneous operators for use in SAS functions and for grouping.  Let’s take a quick tour.

Arithmetic Operators

SymbolDefinitionExampleResult
**exponentiationa**3raise A to the third power
*multiplication12*ymultiply 2 by the value of Y
/divisionvar/5divide the value of VAR by 5
+additionnum+3add 3 to the value of NUM
-subtractionsale-discountsubtract the value of DISCOUNT from the value of SALE
The asterisk (*) is always necessary to indicate multiplication; 2Y and 2(Y) are not valid expressions.
Note:  If a missing value is an operand for an arithmetic operator, the result is a missing value.  You can use parentheses ( ) to control the order in which the expression is evaluated.

Comparison Operators

SymbolMnemonic EquivalentDefinitionExample
=EQequal toa=3
^=NEnot equal to1ane 3
¬=NEnot equal to
~=NEnot equal to
>GTgreater thannum>5
<LTless thannum<8
>=GEgreater than or equal to2sales>=300
<=LEless than or equal to3sales<=100
INequal to one of a listnumin (3, 4, 5)
The symbol that you use for NE depends on your personal computer.
The symbol => is also accepted for compatibility with previous releases of SAS. It is not supported in WHERE clauses or in PROC SQL.
The symbol =< is also accepted for compatibility with previous releases of SAS. It is not supported in WHERE clauses or in PROC SQL.

Note:  You can add a colon (:) modifier to any of the operators to compare only a specified prefix of a character string (name =: ‘St’ would give you all the values of the name variable that start with a capital S followed by a lower case t).
In addition to the above comparison operators, there is the MIN (><) operator which returns the lesser of the two values. The MAX (<>) operator returns the greater of the two values. For example, if A is less than B, then A><B returns the value of A (the minimum or lesser value).

 Logical Operators

SymbolMnemonic EquivalentExample
&AND(a>b & c>d)
|OR1(a>b or c>d)
!OR
¦OR
¬NOT2not(a>b)
NOT
~NOT
The symbol that you use for OR depend on your operating environment.
The symbol that you use for NOT depends on your operating environment.
Note:  Logical operators are also called Boolean operators.  For an AND expression to be true, both sides of the expression must be true (a must be greater than b as well as c must be greater than d, above).  For an OR expression to be true, only one side of the expression must be true (a must be greater than b or c must be greater than d, above).  The NOT logical operator is my favorite.  (Just listen to the name:  The not logicaloperator!  It’s what I tell my husband I’m being when I’m not following his rules of logic.)  Anyway, the NOT logical operator reverses the logic of the AND or OR expression (a cannot be greater than b, above).

Other Useful Symbols

The other useful symbol is the concatenation operator, which is represented by two vertical bars (||, Windows), two broken vertical bars (UNIX), or two exclamation points (!!).  Do remember, however, that the concatenation operator does NOT trim leading or trailing blanks from character values, which can lead to some bizarre results!
I hope this brief tour of some of the most used symbols in SAS code has been helpful.  I’m off now to use my NOT logical operator to good advantage. By the way, the answer to the question at the beginning is z is equal to 3 to the 2nd power or 9 (z=x**y;).

(courtesy: sasblogs)

ss logo-2small
SIGNETSOFT is the best Training center in Bangalore for SAS, SAS clinical, SAS projects, SAS Certification, Advanced Excel, VBA, Java, Clinical Data Management.
A practical approach! and real time expert faculty, good in placement record.
contact us: info@signetsoft.com
mob: 9844559330
Phone: 080-6547 2060

Monday, 29 July 2013

Get a free copy of What’s New in SAS 9.4

 

What’s New in SAS 9.4
SAS 9.4 includes features that are beneficial to all users at your site.
  • For IT departments, SAS 9.4 provides a simplified architecture, increased security, and more deployment options.
  • For SAS administrators, SAS 9.4 provides new management capabilities and administration tools.
  • For data administrators, the integration of the DataFlux products creates a more complete data management solution. Also, new programming languages enable you to manipulate your data and access relational data from various data sources. New programming languages enable you to update data on the database and access relational data from various sources.
  • For SAS programmers, high-performance analytics enable you to quickly analyze large amounts of data. Multi-threading capabilities have also been added so that you can perform analyses on single-machine deployments.
  •  For the business user, reports are available from a variety of mobile devices so that you have the information that you need, when you need it.

Each major SAS release contains new products and hundreds of new features and enhancements. So how do you discover the ones that will make the most difference for you? For SAS 9.4, the Publications team wants to help. For many years, Publications has produced a What’s New book that provides rich detail about the many new things in each SAS release. With so much new, the What’s New book has typically been several hundred pages long. Your challenge has been to glean from that information what the big ticket items are for you, whether you’re an analyst, an IT manager, a data architect, a scientist, etc.
The What’s New in SAS 9.4 book provides an executive summary of the significance of SAS 9.4 in areas such as IT, big data, and analytics. Of course, you can still use the What’s New to find rich detail about the new products and hundreds of new features in SAS 9.4 too.
Get your free copy of What’s New in SAS 9.4 (available as a PDF file, an eBook for your eReader or tablet, or in HTML) here.
Making Information Easier to Find Also for SAS 9.4, the SAS Documentation home page has some new features to help you find information more quickly. For example, when you search, you can now specify up front which SAS product you are using. Doing so can dramatically reduce the number of search hits returned, bringing the information you seek closer to the top of your results. And, the SAS Programmer’s Bookshelf now detects if you’re accessing it from a mobile device and, if so, presents you with a more mobile friendly view.
Finally, a SAS Syntax Index has been added to the SAS Documentation home page. We recommend this index as the fastest way to quickly double-check the syntax for a proc or other SAS language element.


(courtesy: sasblogs)



The best Training in Bangalore for SAS, SAS clinical, SAS projects, SAS Certification, Advanced Excel, VBA, Java, Clinical Data Management is Signetsoft. 
A practical approach! and real time expert faculty, good in placement record.
contact us: info@signetsoft.com
mob: 9844559330

Thursday, 25 April 2013

Happy 1st Anniversary to SIGNETSOFT !!!

Hi Friends,

 

26th April

 

 

new-ss-5a

 This is really a proud & very exciting moment for us when our SIGNETSOFT has completed a year.






A year gone by in the blink of an eye,
training, conversations & laughing,
Wondering what the future holds for us,
We will look back years from now,
With gratitude for having all of you,
& we will know we had a good time.
happy first anniversary…

 

 

new-ss-5a