Showing posts with label sum function in sas. Show all posts
Showing posts with label sum function in sas. Show all posts

Difference Between SAS SUM Function And Using '+' Operator In SAS

Hi All,

Operators :   For any type of calculation, we all are much familiar with Division (/), Multiplication (*), Addition (+) and Substraction (-) which are known as operators. Whenever we are in need to do some calculation in SAS, we use operators. Operators are to do indicated operation between SAS variables or constant values.

Sum Function in SAS :- It returns the sum of non missing and missing arguments.

Ex:          Total = Sum (U,M,A);

Total =  Sum (of  U1 - U10) ;

Total = Sum ( U M A );

"+" Operator in SAS :- It returns a missing value if any of the values (arguments ) are missing.

Difference between SAS Procedure and SAS function

  •  SAS functions would be in need for argument values to be supplied across an observation in SAS dataset.

  •  SAS functions are already written ( pre-written) expressions which gives programming shortcuts for many manipulation and calculation of data

  •  SAS functions are for normal (common ) mathematical operations such as square root, natural log and many more....

  •  SAS Procedures would be in need for one argument value per observation in SAS dataset.

How To Handle Special Missing Values In SAS

Hi All,

 Today we are going to discuss, how to handle missing values in SAS. Yes, I know, you are going to say that you know this thing very well. It’s not about the normal missing values. It’s for SPECIAL MISSING VALUES.

 What is SPECIAL in Missing values:

Suppose I am the owner of a medical shop and I need to enter the name of the medicines which are not available. I am going to take ‘i’ for fever medicine and ‘-‘for cold.

Now I have two type of missing values ‘i’ and ‘-‘. I think you got my point for special missing values.

 If not, then another example is going on:

Suppose in an organization an employee is absent on a day and organization is noting down this one with a notation ‘A’. Some time it happens that employee is in office but he forgot to swipe his details so the system would reflect absent as per the process. But for this type of missing information of absent, organization is having notation like ‘<’.

 Finally you got the point for SPECIAL MISSING VALUES.

 The special missing value is a type of numeric missing value that enables us to show different categories of missing data by using the letters A to Z (A-Z) or an underscore in the data.

 To deal with the special missing values in SAS we have MISSING Statement. We just need to assign all special missing values in Missing Statement;

 Here we go with the example:

Data DSN;

Input id x;

Missing i a _;

Datalines;

1 i

2 0

3 a

4 155

5 _

6 .

7 -24546

8 548

;

Run;


And the output would be like this :

* Here we have Special Missing values ‘I’, ‘a’ and ‘_’.

* DSN is the name of the dataset.

 The order of special missing values can be understand like this: (_) < (.) < (A) < (Z) < (-24546) < (0) < (155).

 *(-24546) is a negative integer and (155) is positive integer.

 You can check the all special values, if it is working correctly in the following example: (Try by yourself just giving you code)

Data calc;

Input x1 x2 x3; (Missing statement is unavailable)

Datalines;

1 2 a

3 2 i

3 1 x

1 1 1

2 2 2

;

Run;




Data Test;

Set calc;

Missing a i x;

Total = x1+x2+x3;

Sumfn= sum(of x1-x3);

Run;




Data exp;

Missing a;

X1 = ._;

X2 = 5;

X3 = .a;

Sum = x1 + x2 + x3;

Sumfn = sum(of x1,x2,x3);

Run;

Note=> Remember if we are assigning a missing value in an expression or in any assignment statement, a period (.) must be used before the special missing value or an underscore otherwise there will be an error in SAS log i.e. "NOTE: Variable _ is uninitialized."  And same happens with a character missing value as well.