SOLUTIONS
True or false: the LAG function can retrieve the previous value of a numeric or character column.
- Answers True
Which data step calculates the difference in Tavg between consecutive rows to generate the
following output table?
a) data TempDiff;
set pg3.weather_sydney_daily2017
(keep=Date Tavg);
if _N_>1 then do;
TempDiff=Tavg-lag(Tavg);
end;
run;
b) data TempDiff(drop=Day1);
set pg3.weather_sydney_daily2017
(keep=Date Tavg);
Day1=lag(Tavg);
if _N_>1 then do;
TempDiff=Tavg-Day1;
end;
run; - Answers b
The LAG function stores previous values in a queue when the LAG function is executed. If the
LAG function is not executed due to a false condition, the previous value is not stored. By using
the LAG function outside of a conditional statement, the previous value is stored.
,Given the following DATA step, what is the value of USNum and WordNum?
data TextCount;
Text='AUSTRALIA, ITALY, AUSTRIA, US';
USNum=count(Text,'US');
WordNum=countw(Text);
run; - Answers USNum = 3 WordNum = 4
The COUNT function counts the number of times that a specified substring appears within a
character string. The COUNTW function counts the number of words in a character string. A
default list of delimiters is used.
Which IF statement subsets ProductName for values containing the standalone word shirt?
a) if find(ProductName, 'Shirt') >0;
b) if findw (ProductName, 'Shirt') = 0;
c) if find(ProductName, ' Shirt ') = 0;
d) if findw(ProductName, 'Shirt', ' ') >0; - Answers d
Choice A returns four rows (rows 2, 3, 4, and 5). Choice B returns one row (row 1). Choice c
returns four rows (rows 1, 3, 4, 5) Choice D returns one row (row 2).
Which statement is false regarding Perl regular expressions?
a) Perl regular expressions are limited to 32 bytes
b) Perl regular expressions consist of metacharacters
c) Perl regular expressions are used in SAS within the PRX functions
d) Perl regular expressions are sequences of strings that define patterns - Answers a
, SAS does not impose a byte size limitation for Perl regular expressions.
True or False: Perl regular expressions in the PRXMATCH function must start and end with a
delimiter. - Answers True
A Perl regular expression within the PRXMATCH function must start and end with a delimiter
such as the forward slash.
What is the value of the column Position?
Position = prxmatch('/Dutch/', 'Sawyer Dutch Kenai'); - Answers 8
PRXMATCH searches for a pattern match and returns the position at which the pattern is found.
The string Dutch is found starting in the eighth position.
True or False: the PRXPARSE function returns a character string that is used by other PRX
functions and call routines. - Answers False
The PRXPARSE function returns a pattern identifier number that is used by other PRX functions
and call routines
Which Perl regular expression replaces the string PG3 with the string PG3M6?
a) 'r/PG3/PG3M6/'
b) 's/PG3/PG3M6/'
c) 's/PG3M6/PG3/'
d) 'r/PG3M6/PG3/' - Answers b
s (specifies a substitution regular expression)
/ (beginning delimiter for regular expression)
PG3 (matches the letters PG3)