Q)What is a method for assigning
first.VAR and last.VAR to the BY groupvariable on
unsorted data?
A) In unsorted data you can't use First. or Last.
Q)How does SAS handle missing
values in: assignment statements, functions, a merge, an update, sort order,
formats, PROCs?
A) Missing values will be assigned as missing in Assignment statement. Sort
order treats missing as second smallest followed by underscore.
Q)Difference between PROC SORT
NODUPKEY and NODUP option?
Remove duplicate records(all fields are same) with
same sort key
Remove other records(all fields may not be same) with same sort key
NODUPRECS
checks for and eliminates duplicate observations.If
you specify this option, then PROC SORT compares all variable values for each
observation to those for the previous observation that was written to the
output data set.If an exact match is found, then the
observation is not written to the output data set.
Nodup/Noduprecs
Duplicate records are not adjacent
data one;
input X $ Y Z ; dataliness;
R 3 9
R3 3
R39
R31
R39
;
proc sort nodup data=one;
by X Y;
run;
proc print data=one;
run;
Obs X Y Z
1 R 3 9
2 R
3
3
3 R
3
9
4 R 3 1
5 R 3 9
Nodup/Noduprecs
Duplicate records are adjacent
Duplicate records are not adjacent but dataset
is sorted on all variables
Output
data one;
input X $ Y Z ; dataliness;
R 3 9
R3 9
R39
R33
R31
;
proc sort nodup data=one;
by X Y;
run;
proc print data=one;
run;
data one;
input X $ Y Z ; dataliness;
R 3 9
R3 3
R39
R31
R39
;
proc sort nodup data=one;
by X Y Z; /*By _all_*/
run;
proc print data=one;
run;
Obs X Y Z
1 R 3 9
2 R
3
3
3 R 3 1
Nodupkey
Duplicate records are adjacent
Duplicate records are not adjacent
Output
data one;
input X $ Y Z ; dataliness;
R 3 9
R3 9
R39
R33
R31
;
proc sort nodupkey data=one;
by X Y;
run;
proc print data=one;
run;
data one;
input X $ Y Z ; dataliness;
R 3 9
R3 3
R39
R31
R39
;
proc sort nodupkey data=one;
by X Y ;
run;
proc print data=one;
run;
Q)How to create many records from one
record? A)using
arrays and with PROC TRANSPOSE
Q)How would you create a data set
with 1 observation and 30 variables from a data set with 30 observations and 1
variable? A)Using
Proc Transpose and also do with the SAS arrays
Q)What is the use of ID Statement in
proc transpose? A)ID statement names the column in
the input file whose row values provide the column names in the output
file.There should only be one variable in an ID statement. Also, the column
used for the ID statement cannot have any duplicate values.
Q)What is the use of var statement in
proc transpose? A)VAR
statement specifies which variables’ values are to be transposed; can be
character and/or numeric variables; if VAR is omitted, Transpose transposes all
numeric variables.
Q)What is the use of By statement in
proc transpose? A)BY
statement names row-identification variable(s) whose values are not transposed;
it requires a preliminary
Q)Descibe Update and Modify
statements? Q)Compare MERGE vs UPDATE vs MODIFY
Definition of
Updating Updating a
SAS data set replaces the values of
variables in master data set with values fromtransaction data set.
If the UPDATEMODE= option in UPDATE statement is set to MISSINGCHECK, then
missing values in a transaction dataset don’t replace existing values in a
master dataset.(default setting is MISSINGCHECK)
We update a data set by using the UPDATE statement along
with a BY statement. Both of the input data sets must be sorted by the variable
that we use in the BY statement.
DATA master;
Update master transaction;
By fieldname
RUN;
Definition of MODIFYING
Modifying
a SAS data set replaces, deletes, or
appends observations in an existing data set. Modifying a SAS data set is
similar to updating a SAS data set, but some differences exist.
Modify statement Control the Update Process using REPLACE,REMOVE
and OUTPUT statements.
When you use the MODIFY statement, there is an implied REPLACE statement at the
bottom of the DATA step instead of an OUTPUT statement.
Using the MODIFY statement, we can update
every
observation in a data set
DATA
SAS-data-set;
MODIFY SAS-data-set;
existing-variable = expression;
RUN;
observations
using a transaction data set and a BY statement
DATA
SAS-data-set;
MODIFY SAS-data-settransaction-data-set;
BY key-variable;
RUN;
When we
submit a DATA step to create a SAS data set that is also named in a MERGE,
UPDATE, or SET statement, SAS creates a second copy of the input data set.Once
execution is done, SAS deletes the original copy of the data set. As a result,the original data set is replaced by the new data set.
When we
submit a DATA step to create a SAS data set that is also named in a MERGE,
UPDATE, or SET statement, SAS creates a second copy of the input data set.Once
execution is done, SAS deletes the original copy of the data set. As a result,the original data set is replaced by the new data set.
when we submit a DATA step to create a SAS data set that is also
named in the MODIFY statement, SAS does not create a second copy of
data but
instead updates the data set in place.
Can
create or delete variables
Yes
The new data set
can contain a different set of
variables than the original data set and the attributes of the variables
in the new data set can be different from those of the original data set.
Yes
The new data set
can contain a different set of
variables than the original data set and the attributes of the variables
in the new data set can be different from those of the original data set.
No
Any variables can be added to PDV, but they are not written to the
data set. So, the set of variables in the data set does not change when the
data is modified.
Data sets must
be sorted or indexed
Match-merge:
Yes
One-to-one merge: No
Yes
No
BY values must
be unique
No
Master
data set: Yes
Transaction data set: No
No
Number
of data sets combined
Any number
2
2
Processing
missing values
Overwrites
nonmissing values from first data set with missing values from second data
set