%let paidval=n; proc means data=sasuser.all sum maxdec=0; where paid="&paidval"; var fee; class course_title; title "Uncollected Fees for Each Course"; run;
163 %let paidval=n; 164 proc means data=sasuser.all sum maxdec=0; 165 where paid="&paidval"; 166 var fee; 167 class course_title; 168 title "Uncollected Fees for Each Course"; 169 run; NOTE: No observations were selected from data set SASUSER.ALL. |
paidval
was specified
in lowercase, the WHERE expression finds no matching observations.
All the values of the data set variable Paid
are
stored in uppercase.
%let paidval=n;
proc means data=sasuser.all sum maxdec=0;
where paid="%upcase(&paidval)";
var fee;
class course_title;
title "Uncollected Fees for Each Course";
run;
%let a=begin; %let b=%nrstr(&a); %put UPCASE produces: %upcase(&b); %put QUPCASE produces: %qupcase(&b);
begin
. The second %PUT statement
uses the %QUPCASE function, which masks the ampersand in the resolved
value of the macro variable b
so that this value is not treated
as another macro variable reference. Executing these statements produces
the following messages in the SAS log.
General form, %SUBSTR
function:
%SUBSTR (argument,
position<,n>)
argument
is a character string
or a text expression from which a substring is returned.
position
is an integer or an
expression (text, logical, or mathematical) that yields an integer,
which specifies the position of the first character in the substring.
n
is an optional integer
or an expression (text, logical, or mathematical) that yields an integer
that specifies the number of characters in the substring.
|
date
has the
value 05JAN2002
.
%substr(&date,3)
returns
the value JAN2002
.
%substr(&date,3,3)
returns
the value JAN
.
%substr(&date,3,9)
returns
the value JAN2002
and produces a warning
message.
position
and n can
also be the result of a mathematical expression that yields an integer.
For example, %substr(&var,%length(&var)-1)
returns
the last two characters of the value of the macro variable var
.
* Update the class schedule based on previous ; data update_schedule; set sasuser.schedule; begin_date + 3652; run;
* Print a list of courses that started this month;
proc print data=update_schedule;
where begin_date between
"01%substr(&sysdate9,3)"d and
"&sysdate9"d;
title "All Courses Held So Far This Month";
title2 "(as of &sysdate9)";
run;
%let a=one; %let b=two; %let c=%nrstr(&a &b); %put C: &c; %put With SUBSTR: %substr(&c,1,2); %put With QSUBSTR: %qsubstr(&c,1,2);
General form, %INDEX
function:
%INDEX (source,string)
source and string
both are character
strings or text expressions that can include
|
0
when
there is no pattern match.
General form, %SCAN
function:
%SCAN (argument,
n<,delimiters>)
argument
consists of constant
text, macro variable references, macro functions, or macro calls.
n
is an integer or a
text expression that yields an integer, which specifies the position
of the word to return. If n is
greater than the number of words in argument,
the functions return a null string.
delimiters
specifies an optional
list of one or more characters that separate "words" or
text expressions that yield one or more characters.
|
blank
. < ( + & ! $ * ) ; ^ - / , % |
blank
. < ( + | & ! $ * ) ; ¬ - / , % ¦ ¢
data work.thisyear; set sasuser.schedule; where year(begin_date) = year("&sysdate9"d); run; %let libref=%scan(&syslast,1,.); %let dsname=%scan(&syslast,2,.); proc datasets lib=&libref nolist; title "Contents of the Data Set &syslast"; contents data=&dsname; run; quit;