Date: Mon, 14 Dec 1998 10:41:01 -0600
Reply-To: Jack Hamilton <jack_hamilton@FIRSTHEALTH.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Jack Hamilton <jack_hamilton@FIRSTHEALTH.COM>
Subject: Re: QUOTE function with SELECT/INTO in PROC SQL
Content-Type: text/plain; charset=US-ASCII
Gorrell_P <Gorrell_P@BLS.GOV> wrote:
>I assume I'm missing something basic, but I don't understand the use of the
>QUOTE function when creating macrovariables with PROC SQL.
>The SAS Macro Language Reference (p. 186) has the following example:
> select distinct quote(style)
> into :types separated by ', '
> from sasuser.houses;
That appears to be an error.
>%put Types of houses=&types.;
>LOG: Types of houses=CONDO, RANCH, SPLIT, TWOSTORY
I would expect to see
Types of houses="CONDO", "RANCH", "SPLIT", "TWOSTORY"
>I cannot recreate this output to the LOG. Here's my simple example, using
>dataset ONE, which contains the character variable v1.
>proc sql noprint;
> select v1
> into :var1 separated by ', '
> from one;
> select quote( v1)
> into :qvar1 separated by ', '
> from one;
>%put Values of v1 = &var1;
>Values of v1 = a, b, c, d
>%put Values of quoted v1 = &qvar1;
>Values of quoted v1 = "a", "b", "c", "d"
That's what I would expect.
>Two questions: (i) why does my use of QUOTE produce a list with double
>quotes, but not the Reference example;
The reference example appears to be wrong. If a job produces a different
answer than the example, suspect the example as well as the job.
>(ii) in what contexts will the use
>and non-use of QUOTE produce different output?
QUOTE(X) should always be different from X.
>For example, if I add a
>WHERE clause (e.g. where v1='a'), I get the same subsetting effect whether
>or not I use the QUOTE function.
I'm not entirely sure what you're trying to do; your example doesn't do
Whether you use the QUOTE function in the SELECT clause will have no
effect on which values are selected by the WHERE clause.
If you're trying to create the values that will later be used in an IN
condition, you would typically use the QUOTE function for string
variables, and not use it for numeric variables.
>Thanks in advance for letting me know what I'm missing.
You might be overlooking a distinction between a variable's name and its