You are on page 1of 22

https://documentation.sas.com/?

docsetId=lefunctionsref&docsetTarget=n0xk6tl87f4b4qn1sp1ywen
1ntan.htm&docsetVersion=9.4&locale=en

Q) What is the PDV?

 The Program Data Vector is a logical area of memory. that is created during the data step
processing.
 SAS builds a SAS dataset by reading one observation at. a time into the PDV and, unless
given code to do otherwise, writes the observation to a target dataset.
 Input Buffer: In case of reading a data from raw file an input buffer is created to a hold a
record of external file whereas while reading data from SAS data set, it is not. Input buffer
refers to a logical concept not a physical storage area.

Processing a DATA Step: A Walkthrough


Sample DATA Step

The following statements provide an example of a DATA step that reads raw data, calculates
totals, and creates a data set:

data total_points (drop=TeamName); 1


input TeamName $ ParticipantName $ Event1 Event2 Event3; 2
TeamTotal + (Event1 + Event2 + Event3); 3
datalines;
Knights Sue 6 8 8
Kings Jane 9 7 8
Knights John 7 7 7
Knights Lisa 8 9 9
Knights Fran 7 6 6
Knights Walter 9 8 10
;
The DROP= data set option prevents the variable TeamName from being written to the
output SAS data set called TOTAL_POINTS.

The INPUT statement describes the data by giving a name to each variable, identifying
its data type (character or numeric), and identifying its relative location in the data record.

The Sum statement accumulates the scores for three events in the variable TeamTotal.

Creating the Input Buffer and the Program Data Vector

When DATA step statements are compiled, SAS determines whether to create an input
buffer. If the input file contains raw data (as in the example above), SAS creates an input
buffer to hold the data before moving the data to the program data vector (PDV). (If the input
file is a SAS data set, however, SAS does not create an input buffer. SAS writes the input
data directly to the PDV.)

The PDV contains all the variables in the input data set, the variables created in DATA step
statements, and the two variables, _N_ and _ERROR_, that are automatically generated for
every DATA step. The _N_ variable represents the number of times the DATA step has
iterated. The _ERROR_ variable acts like a binary switch whose value is 0 if no errors exist
in the DATA step, or 1 if one or more errors exist. The following figure shows the Input
Buffer and the program data vector after DATA step compilation.

Input Buffer and Program Data Vector

Variables that are created by the INPUT and the Sum statements (TeamName,
ParticipantName, Event1, Event2, Event3, and TeamTotal) are set to missing initially. Note
that in this representation, numeric variables are initialized with a period and character
variables are initialized with blanks. The automatic variable _N_ is set to 1; the automatic
variable _ERROR_ is set to 0.

The variable TeamName is marked Drop in the PDV because of the DROP= data set option
in the DATA statement. Dropped variables are not written to the SAS data set. The _N_ and
_ERROR_ variables are dropped because automatic variables created by the DATA step are
not written to a SAS data set. See SAS Variables for details about automatic variables.

Reading a Record

SAS reads the first data line into the input buffer. The input pointer, which SAS uses to keep
its place as it reads data from the input buffer, is positioned at the beginning of the buffer,
ready to read the data record. The following figure shows the position of the input pointer in
the input buffer before SAS reads the data.

Position of the Pointer in the Input Buffer Before SAS Reads Data

The INPUT statement then reads data values from the record in the input buffer and writes
them to the PDV where they become variable values. The following figure shows both the
position of the pointer in the input buffer, and the values in the PDV after SAS reads the first
record.

Values from the First Record are Read into the Program Data Vector
After the INPUT statement reads a value for each variable, SAS executes the Sum statement.
SAS computes a value for the variable TeamTotal and writes it to the PDV. The following
figure shows the PDV with all of its values before SAS writes the observation to the data set.

Program Data Vector with Computed Value of the Sum Statement

Writing an Observation to the SAS Data Set

When SAS executes the last statement in the DATA step, all values in the PDV, except those
marked to be dropped, are written as a single observation to the data set TOTAL_POINTS.
The following figure shows the first observation in the TOTAL_POINTS data set.

The First Observation in Data Set TOTAL_POINTS

SAS then returns to the DATA statement to begin the next iteration. SAS resets the values in
the PDV in the following way:

 The values of variables created by the INPUT statement are set to missing.
 The value created by the Sum statement is automatically retained.
 The value of the automatic variable _N_ is incremented by 1, and the value of
_ERROR_ is reset to 0.

The following figure shows the current values in the PDV.

Current Values in the Program Data Vector


Reading the Next Record

SAS reads the next record into the input buffer. The INPUT statement reads the data values
from the input buffer and writes them to the PDV. The Sum statement adds the values of
Event1, Event2, and Event3 to TeamTotal. The value of 2 for variable _N_ indicates that
SAS is beginning the second iteration of the DATA step. The following figure shows the
input buffer, the PDV for the second record, and the SAS data set with the first two
observations.

Input Buffer, Program Data Vector, and First Two Observations

As SAS continues to read records, the value in TeamTotal grows larger as more participant
scores are added to the variable. _N_ is incremented at the beginning of each iteration of the
DATA step. This process continues until SAS reaches the end of the input file.

When the DATA Step Finishes Executing

The DATA step stops executing after it processes the last input record. You can use PROC
PRINT to print the output in the TOTAL_POINTS data set:

Output from the Walkthrough DATA Step

Total Team Scores


1

Participant Team
Obs Name Event1 Event2 Event3 Total

1 Sue 6 8 8 22
2 Jane 9 7 8 46
3 John 7 7 7 67
4 Lisa 8 9 9 93
5 Fran 7 6 6 112
6 Walter 9 8 10 139

Q) Functions used to perform specific tasks are
1) Substr  substring :
The SAS data step function SUBSTR (commonly pronounced “sub- string”) function is used to work
with a specific position or positions of characters within a defined character variable. The function
focuses on a portion of a string and can go on either side of the “=” sign in a data step statement.

2)Compress : COMPRESS function is basically used to compress/removes all the spaces/blanks in a


character string. In other words, it removes leading, between and trailing spaces from the strings.
The COMPRESS function allows null arguments. A null argument is treated as a string that features a
length of zero.

COMPRESS Function
Returns a character string with specified characters removed from the original string.

Character
Categories:
CAS

This function is assigned an I18N Level 0 status, and is designed for SBCS data. Do not
Restriction: use this function to process DBCS or MBCS data. For more information, see
Internationalization Compatibility.

Note: This function supports the VARCHAR type.

Tip: The DBCS equivalent function is KCOMPRESS.

Syntax
COMPRESS(source <, characters> <, modifier(s)>)

Required Argument

source

specifies a character constant, variable, or expression from which specified characters are
removed.
Optional Arguments

characters

specifies a character constant, variable, or expression that initializes a list of characters.

By default, the characters in this list are removed from the source argument. If you specify the K
modifier in the third argument, only the characters in this list are kept in the result.

Tip : You can add more characters to this list by using other modifiers in the third argument.

Tip :Enclose a literal string of characters in quotation marks.

modifier

specifies a character constant, variable, or expression in which each non-blank character


modifies the action of the COMPRESS function. Blanks are ignored. The following
characters can be used as modifiers:

a
or adds alphabetic characters to the list of characters.
A

c
or adds control characters to the list of characters.
C

d
or adds digits to the list of characters.
D

f or
adds the underscore character and English letters to the list of characters.
F

g
or adds graphic characters to the list of characters.
G

h
or adds a horizontal tab to the list of characters.
H

i or
ignores the case of the characters to be kept or removed.
I

k keeps the characters in the list instead of removing them.


or
K

l or
adds lowercase letters to the list of characters.
L

n
or adds digits, the underscore character, and English letters to the list of characters.
N

processes the second and third arguments once rather than every time the COMPRESS function
o
is called. Using the O modifier in the DATA step (excluding WHERE clauses), or in the SQL
or
procedure, can make COMPRESS run much faster when you call it in a loop where the second
O
and third arguments do not change.

p
or adds punctuation marks to the list of characters.
P

s
adds space characters (blank, horizontal tab, vertical tab, carriage return, line feed, form feed,
or
and NBSP ('A0'x, or 160 decimal ASCII) to the list of characters.
S

t or
trims trailing blanks from the first and second arguments.
T

u
or adds uppercase letters to the list of characters.
U

w
or adds printable characters to the list of characters.
W

x
or adds hexadecimal characters to the list of characters.
X

Tip

If the modifier is a constant, enclose it in quotation marks. Specify multiple constants in a single set
of quotation marks. Modifier can also be expressed as a variable or an expression.

Details
Length of Returned Variable

The Basics
Length of Returned Variable
In a DATA step, if the COMPRESS function returns a value to a variable that has not previously been
assigned a length, that variable is given the length of the first argument.

The Basics
The COMPRESS function allows null arguments. A null argument is treated as a string that has a
length of 0.

Based on the number of arguments, the COMPRESS function works as follows:

Number of
Result
Arguments

All blanks have been removed from the argument. If the argument is
only the first completely blank, the result is a string with a length of 0. If you assign the
argument, source result to a character variable with a fixed length, the value of that variable is
padded with blanks to fill its defined length.

the first two


All characters that appear in the second argument are removed from the
arguments, source
result.
and characters

three arguments,
The K modifier (specified in the third argument) determines whether the
source, chars, and
characters in the second argument are kept or removed from the result.
modifier(s)

The COMPRESS function compiles a list of characters to keep or remove, comprising the characters
in the second argument plus any types of characters that are specified by the modifiers. For
example, the D modifier specifies digits. Both of the following function calls remove digits from the
result:

compress(source, "1234567890");
compress(source, , "d");
To remove digits and plus or minus signs, you can use either of these function calls:

compress(source, "1234567890+-");
compress(source, "+-", "d");

Examples
Example 1: Compressing Blanks
data one;
a='AB C D ';
b=compress(a);
put b=;
run;
The preceding statements produce this result:

b=ABCD
Example 2: Compressing Lowercase Letters
data _null_;
x='123–4567–8901 B 234–5678–9012 c';
y=compress(x, 'ABCD', 'l');
put y=;
run;
The preceding statements produce this result:

y=123-4567-8901 234-5678-9012

Example 3: Compressing Space Characters


data one;
x='1 2 3 4 5';
y=compress(x, , 's');
put y=;
run;
The preceding statements produce this result:

y=12345

Example 4: Keeping Characters in the List


data one;
x='Math A English B Physics A';
y=compress(x, 'ABCD', 'k');
put y=;
run;
The preceding statements produce this result:

y=ABA

Example 5: Compressing a String and Returning a Length of 0


data _null_;
x='';
l=lengthn(compress(x));
put l=;
run;
The preceding statements produce this result:

l=0

3) Compbl :

COMPBL Function
Removes multiple blanks from a character string.

Character
Categories:
CAS

This function is assigned an I18N Level 2 status, and is designed for use with SBCS, DBCS,
Restriction:
and MBCS (UTF8). For more information, see Internationalization Compatibility.
Interaction: This function supports the VARCHAR type.

Table of Contents

Syntax
COMPBL(source)

Required Argument

source

specifies a character constant, variable, or expression to compress.

Details
Length of Returned Variable

The Basics

Length of Returned Variable


In a DATA step, if the COMPBL function returns a value to a variable that has not previously been
assigned a length, the length of that variable defaults to the length of the first argument.

The Basics
The COMPBL function removes multiple blanks in a character string by translating each occurrence
of two or more consecutive blanks into a single blank.

Comparisons
The COMPRESS function removes every occurrence of the specific character from a string. If you
specify a blank as the character to remove from the source string, the COMPRESS function removes
all blanks from the source string, The COMPBL function compresses multiple blanks to a single blank
and has no effect on a single blank.

Examples
Example 1
data one;
string='Hey
Diddle Diddle';
string=compbl(string);
put string=;
run;
The preceding statements produce this result:

string=HeyDiddle Diddle

Example 2
data one;
string='125 E Main St';
length address $10;
address=compbl(string);
put address=;
run;
The preceding statements produce this result:

address=125 E Main

LEFT Function
Left-aligns a character string.

Character
Categories:
CAS

This function is assigned an I18N Level 2 status, and is designed for use with SBCS, DBCS,
Restriction:
and MBCS (UTF8). For more information, see Internationalization Compatibility.

Note: This function supports the VARCHAR type.

Tip: DBCS equivalent function is KLEFT . See DBCS Compatibility.

See Also

Syntax
LEFT(argument)

Required Argument

argument

specifies a character constant, variable, or expression.

Details
The Basics
In a DATA step, if the LEFT function returns a value to a variable that has not previously been
assigned a length, then that variable is given the length of the argument.

LEFT returns an argument with leading blanks moved to the end of the value. The argument's length
does not change.

DBCS Compatibility
The LEFT function left-aligns a character string. You can use the LEFT function in most cases. If an
application can be executed in an ASCII environment, or if the application does not manipulate
character strings, then using the LEFT function rather than the KLEFT function.

Example
data one;
a=' DUE DATE';
b=left(a);
put b=;
run;
These statements produce this result:
b=DUE DATE

RIGHT Function
Right aligns a character expression.

Character
Categories:
CAS

This function is assigned an I18N Level 2 status, and is designed for use with SBCS, DBCS,
Restriction:
and MBCS (UTF8). For more information, see Internationalization Compatibility.

Note: This function is not supported in a DATA step that runs in CAS.

Tip: DBCS equivalent function is KRIGHT.

Syntax
RIGHT(argument)

Required Argument

argument

specifies a character constant, variable, or expression.

Details
In a DATA step, if the RIGHT function returns a value to a variable that has not previously been
assigned a length, then that variable is given the length of the first argument.

The RIGHT function returns an argument with trailing blanks moved to the start of the value. The
length of the result is the same as the length of the argument.

Example
data new;
length a $12 b $15;
a='Due Date ';
b='*'||right(a);
put a= $12. b= $15.;
run;
These SAS statements produce these results:

a=Due Date b=* Due Date


TRIM Function
Removes trailing blanks from a character string and returns one blank if the string is missing.

Character
Categories:
CAS

This function is assigned an I18N Level 2 status, and is designed for use with SBCS, DBCS,
Restriction:
and MBCS (UTF8). For more information, see Internationalization Compatibility.

Note: This function supports the VARCHAR type.

The DBCS equivalent function is KTRIM Function in SAS National Language Support
Tip:
(NLS): Reference Guide.

Syntax
TRIM(argument)

Required Argument

argument

specifies a character constant, variable, or expression.

Details
Length of Returned Variable

The Basics

Length of Returned Variable


In a DATA step, if the TRIM function returns a value to a variable that has not previously been
assigned a length, then that variable is given the length of the argument.

The Basics
TRIM copies a character argument, removes trailing blanks, and returns the trimmed argument as a
result. If the argument is blank, TRIM returns one blank. TRIM is useful for concatenating because
concatenation does not remove trailing blanks.

Assigning the results of TRIM to a variable does not affect the length of the receiving variable. If the
trimmed value is shorter than the length of the receiving variable, SAS pads the value with new
blanks as it assigns the value to the variable.

Examples
Example 1: Removing Trailing Blanks
The following statements and this data line produce these results:
data test;
input part1 $ 1-10 part2 $ 11-20;
hasblank=part1||part2;
noblank=trim(part1)||part2;
put hasblank=;
put noblank=;
datalines;
apple sauce
;
These statements produce these results:

hasblank=apple sauce
noblank=applesauce

Example 2: Concatenating a Blank Character Expression


data new;
x="A"||trim(" ")||"B";
z=" ";
y=">"||trim(z)||"<";
put x= y=;
run;
These statements produce these results:

x=A B y=> <

STRIP Function
Returns a character string with all leading and trailing blanks removed.

Character
Categories:
CAS

This function is assigned an I18N Level 1 status. If possible, avoid I18N Level 1 functions
if you are using a non-English language. Under certain circumstances, the I18N Level 1
Restriction: functions might not work correctly with Double-Byte Character Set (DBCS) or Multi-Byte
Character Set (MBCS) encodings. For more information, see Internationalization
Compatibility.

Note: This function supports the VARCHAR type.

Syntax
STRIP(string)

Required Argument

String : is a character constant, variable, or expression.

Details
Length of Returned Variable
The Basics

Length of Returned Variable


In a DATA step, if the STRIP function returns a value to a variable that has not previously been
assigned a length, then that variable is given the length of the argument.

The Basics
The STRIP function returns the argument with all leading and trailing blanks removed.

Assigning the results of STRIP to a variable does not affect the length of the receiving variable. If the
value that is trimmed is shorter than the length of the receiving variable, SAS pads the value with
new trailing blanks.

Note: The STRIP function is useful for concatenation because the concatenation operator does not
remove leading or trailing blanks.

Comparisons
The following list compares the STRIP function with the TRIM and TRIMN functions:

 For strings that are blank, the STRIP and TRIMN functions return a string with a length of
zero, whereas the TRIM function returns a single blank.
 For strings that lack leading blanks, the STRIP and TRIMN functions return the same value.
 For strings that lack leading blanks but have at least one non-blank character, the STRIP and
TRIM functions return the same value.

Note: STRIP(string) returns the same result as TRIMN(LEFT(string)), but the STRIP function
runs faster.

Example
This example shows the results of using the STRIP function to delete leading and trailing blanks.

data lengthn;
input string $char8.;
original='*' || string || '*';
stripped='*' || strip(string) || '*';
datalines;
abcd
abcd
abcd
abcdefgh
x y z
;
proc print data=lengthn;
run;
Output from the STRIP Function

LAG Function
Returns values from a queue.
Special
Categories:
CAS

Note: The VARCHAR type is not supported for arguments in the LAG function.

Table of Contents

Syntax

Required Argument

Optional Argument

Details

The Basics

Memory Limit for the LAG Function

Examples

Example 1: Generating Two Lagged Values

Example 2: Generating Multiple Lagged Values in BY Groups

Example 3: Computing the Moving Average of a Variable through the Entire Data Set

Example 4: Computing the Moving Average of a Variable of the Last n Observations

Example 5: Computing the Moving Average of a Variable of the Last n Observations within a BY
Group

Example 6: Generating a Fibonacci Sequence of Numbers

Example 7: Using Expressions for the LAG Function Argument

See Also

Syntax
LAG <n> (argument)

Required Argument

argument

specifies a numeric or character constant, variable, or expression.


Optional Argument

specifies the number of lagged values.

Details
The Basics

Memory Limit for the LAG Function

The Basics
If the LAG function returns a value to a character variable that has not yet been assigned a length, by
default the variable is assigned the same length as the variable used in the argument.

The LAG functions, LAG1, LAG2, ..., LAGn return values from a queue. LAG1 can also be written as
LAG. A LAGn function stores a value in a queue and returns a value stored previously in that queue.
Each occurrence of a LAGn function in a program generates its own queue of values.

The queue for each occurrence of LAGn is initialized with n missing values, where n is the length of
the queue (for example, a LAG2 queue is initialized with two missing values). When an occurrence of
LAGn is executed, the value at the top of its queue is removed and returned, the remaining values
are shifted upward, and the new value of the argument is placed at the bottom of the queue. Hence,
missing values are returned for the first n executions of each occurrence of LAGn, after which the
lagged values of the argument begin to appear.

Note: Storing values at the bottom of the queue and returning values from the top of the queue
occurs only when the function is executed. An occurrence of the LAGn function that is executed
conditionally stores and return values only from the observations for which the condition is satisfied.

If the argument of LAGn is an array name, a separate queue is maintained for each variable in the
array.

Memory Limit for the LAG Function


When the LAG function is compiled, SAS allocates memory in a queue to hold the values of the
variable that is listed in the LAG function. For example, if the variable in function LAG100(x) is
numeric with a length of 8 bytes, then the memory that is needed is 8 times 100, or 800 bytes.
Therefore, the memory limit for the LAG function is based on the memory that SAS allocates, which
varies with different operating environments.

Examples
Example 1: Generating Two Lagged Values
The following program generates two lagged values for each observation.

data one;
input x @@;
y=lag1(x);
z=lag2(x);
datalines;
1 2 3 4 5 6
;
proc print data=one;
title 'LAG Output';
run;
Output from Generating Two Lagged Values

LAG1 returns one missing value and the values of X (lagged once). LAG2 returns two missing values
and the values of X (lagged twice).

Example 2: Generating Multiple Lagged Values in BY Groups


The following example shows how to generate up to three lagged values within each BY group.

/**************************************************************************
*/
/* This program generates up to three lagged values. By increasing the
*/
/* size of the array and the number of assignment statements that use
*/
/* the LAGn functions, you can generate as many lagged values as needed.
*/
/**************************************************************************
*/
/* Create starting data. */
data old;
input start end;
datalines;
1 1
1 2
1 3
1 4
1 5
1 6
1 7
2 1
2 2
3 1
3 2
3 3
3 4
3 5
;
data new(drop=i count);
set old;
by start;
/* Create and assign values to three new variables. Use ENDLAG1- */
/* ENDLAG3 to store lagged values of END, from the most recent to the */
/* third preceding value. */
array x(*) endlag1-endlag3;
endlag1=lag1(end);
endlag2=lag2(end);
endlag3=lag3(end);
/* Reset COUNT at the start of each new BY-Group */
if first.start then count=1;
/* On each iteration, set to missing array elements */
/* that have not yet received a lagged value for the */
/* current BY-Group. Increase count by 1. */
do i=count to dim(x);
x(i)=.;
end;
count + 1;
run;
proc print;
run;

Output from Generating Three Lagged Values

Example 3: Computing the Moving Average of a Variable through the Entire Data Set
The following example computes the moving average of a variable through the entire data set.

data x;
do x=1 to 10;
output;
end;
run;
/* Compute the moving average of the entire data set. */
data avg;
retain s 0;
set x;
s=s+x;
a=s/_n_;
run;
proc print;
run;
Output from Computing the Moving Average of a Variable

Example 4: Computing the Moving Average of a Variable of the Last n Observations


The following example computes the moving average of a variable of the last n observations.

data x;
do x=1 to 10;
output;
end;
run;
%let n=5;
data avg (drop=s);
retain s;
set x;
s=sum (s, x, -lag&n(x)) ;
a=s / min(_n_, &n);
run;
proc print;
run;
Computing the Moving Average of a Variable of the last n observations.
Example 5: Computing the Moving Average of a Variable of the Last n Observations within
a BY Group
The following example computes the moving average of a variable of the last n observations within a
BY group.

data x;
do x=1 to 10;
output;
end;
run;
data ds1;
do patient='A','B','C';
do month=1 to 7;
num=int(ranuni(0)*10);
output;
end;
end;
run;
proc sort;
by patient;
%let n = 4;
data ds2;
set ds1;
by patient;
retain num_sum 0;
if first.patient then do;
count=0;
num_sum=0;
end;
count+1;
last&n=lag&n(num);
if count gt &n then num_sum=sum(num_sum, num, -last&n);
else num_sum=sum(num_sum, num);
if count ge &n then mov_aver=num_sum/&n;
else mov_aver=.;
run;
proc print;
run;
Computing the Moving Average of a Variable of the last n observations within a BY group

Example 6: Generating a Fibonacci Sequence of Numbers


The following example generates a Fibonacci sequence of numbers. You start with 0 and 1, and then
add the two previous Fibonacci numbers to generate the next Fibonacci number.

data _null_;
put 'Fibonacci Sequence';
n=1;
f=1;
put n= f=;
do n=2 to 10;
f=sum(f, lag(f));
put n= f=;
end;
run;
SAS writes the following output to the log:
Fibonacci Sequence
n=1 f=1
n=2 f=1
n=3 f=2
n=4 f=3
n=5 f=5
n=6 f=8
n=7 f=13
n=8 f=21
n=9 f=34
n=10 f=55

Example 7: Using Expressions for the LAG Function Argument


The following program uses an expression for the value of argument and creates a data set that
contains the values for X, Y, and Z. LAG dequeues the previous values of the expression and
enqueues the current value.

data one;
input X @@;
Y=lag1(x+10);
Z=lag2(x);
datalines;
1 2 3 4 5 6
;
proc print;
title 'Lag Output: Using an Expression';
run;
Output from the LAG Function: Using an Expression

SUM Function
Returns the sum of the nonmissing arguments.

Descriptive Statistics
Categories:
CAS

Table of Contents

Syntax

Required Argument

Example

Syntax
SUM(argument-1 <, argument-2, ...>)
Required Argument

argument

specifies a numeric constant, variable, or expression. If all the arguments have missing
values, then one of these actions occurs:

 If you use only one argument, the value of that argument is returned.
 If you use two or more arguments, a standard missing value (.) is returned.

Otherwise, the result is the sum of the nonmissing values. The argument list can consist of a variable
list.

Example
data one;
input val1 val2 val3 val4;
datalines;
4 9 3 8
;

data new;
set one;
x1=sum(4, 9, 3, 8);
x2=sum(val1,val2,val3,val4, .);
x3=sum(56);
x4=sum(of val1-val2);

y1=34; y2=12; y3=74; y4=39;


result=sum(of val1-val4, of y1-y4);
x5=sum(of val1-val3, 5);
x6=sum(val1-val2);
x7=sum(of y:);
put _all_;
run;
These statements produce these results:

val1=4 val2=9 val3=3 val4=8 x1=24 x2=24 x3=56 x4=13 y1=34 y2=12 y3=74 y4=39
result=183 x5=21 x6=-5
x7=159 _ERROR_=0 _N_=1

You might also like