由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - Help! sas macro qeustions.
相关主题
sas questionSAS Base 123题中47和112题疑问
一个sas问题What is wrong with this?
有关sas macro 的问题Help: an I/O ERROR occured
Help needed! What sas function can read char. date HH:DD:SS:SSS to numeric?怎么去掉一个CHARACTER VAR中的delimiters
SAS菜鸟请教substr请教一个sas编程问题
sas一问一个sas问题的解决方法讨论
怎样在data step跳过格式不对的data record?哪位前辈能发一份机经BASIC, 就要考了。
SAS9.2 - Z format请教sas高人(数据读入)
相关话题的讨论汇总
话题: select话题: informat话题: sql话题: error话题: bquote
进入Statistics版参与讨论
1 (共1页)
s******r
发帖数: 1524
1
I have one macro written like
proc sql;
create table as
select %bquote("&&M&i") informat=$50. as test1,
cnt from
select * from connection to sql(
****
);
quit;run;
&&M&i is supposed to be : and (a>=1 and b>=2)
The code failed and log shows as
select "and ( a>=1 and b>=2)" informat= as test1,
$50. disappeared.
while I changed code to
proc sql;
create table as
select %bquote("&&M&i") as test1 informat=$50.,
cnt from
select * from connection to sql(
****
);
quit;run;
I got
"and (a>=1 and b>=2) "
_
22
___
202
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted
string, a numeric constant, a datetime constant,
a missing value, (, *, +, -, BTRIM, CALCULATED, CASE, EXISTS,
INPUT, NOT, PUT, SUBSTRING, TRANSLATE, USER, ^, ~.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
While I copied all log transferred SAS code and it actually works. Any idea
how to fix the problem?
Thank a lot.
a*****3
发帖数: 601
2
第一个and干什么用的 没看懂。
s******y
发帖数: 352
3

correct me if i am wrong. I don't think you need macro quoting here.
plus, you used double quotations as the argument for %bquote. the argument
will be resolved at the compile time, though you used a execution time
quoting function.
the resolved &&M&I will stay within the quotation marks.it will not cause
any problem at all. I can not see why you need to mask special characters.
the error message has nothing to do with the sql pass through as your select
statement is applied to the result set returned by the native database.
just use %unquote function to unquote the masked characters to see if it
will dismiss the error message. if not, you need to provide more information
.

【在 s******r 的大作中提到】
: I have one macro written like
: proc sql;
: create table as
: select %bquote("&&M&i") informat=$50. as test1,
: cnt from
: select * from connection to sql(
: ****
: );
: quit;run;
: &&M&i is supposed to be : and (a>=1 and b>=2)

a*****3
发帖数: 601
4
and (a>=1 and b>=2) 是合法变量名么? 谁来说说?
s******y
发帖数: 352
5
To your question. yes, it is:
option validvarname=any;
data a;
'and (a>=1 and b>=2)'n='hello alex';
run;
proc contents;
run;
but I don't think OP wants to add a column with that name. my best guess is
OP want to pass a condition dynamically to somewhere.
BAOZI please!
a*****3
发帖数: 601
6
可是从log上看,宏变量似乎已经成功resolve了 。 no matter if any quoting
functions should be used or not.

: will be resolved at the compile time, though you used a execution time:
quoting function.
any problem at all. I can not see why you need to mask special characters.:
the error message has nothing to do with the sql pass through as your
select: statement is applied to the result set returned by the native
database.: just use %unquote function to unquote the masked characters to
see if it: will dismiss the error message. if not, you need to provide more
information

【在 s******y 的大作中提到】
: To your question. yes, it is:
: option validvarname=any;
: data a;
: 'and (a>=1 and b>=2)'n='hello alex';
: run;
: proc contents;
: run;
: but I don't think OP wants to add a column with that name. my best guess is
: OP want to pass a condition dynamically to somewhere.
: BAOZI please!

s******y
发帖数: 352
7
Right. that is why I suggest to use %unquote to unmask the masked chars.
especially the "". most of time, the masked char will be automatically
unmasked so that the SAS tokenizer can parse the statement. but some time,
the auto conversion failed. so you need to unquote them manually.
BAOZI please.

.:
more

【在 a*****3 的大作中提到】
: 可是从log上看,宏变量似乎已经成功resolve了 。 no matter if any quoting
: functions should be used or not.
:
: : will be resolved at the compile time, though you used a execution time:
: quoting function.
: any problem at all. I can not see why you need to mask special characters.:
: the error message has nothing to do with the sql pass through as your
: select: statement is applied to the result set returned by the native
: database.: just use %unquote function to unquote the masked characters to
: see if it: will dismiss the error message. if not, you need to provide more

a*****3
发帖数: 601
8
楼上博彩不是已经赢了么,又要钱做什么?
s******y
发帖数: 352
9
还有2场。 下下星期的风险较高, 当然回报也高。 我是想all-in。 然后征些包子赌
第二场。 不然我早睡觉去了。不建议你参与这两次。 血本乌龟的可能性太高
s******r
发帖数: 1524
10
yeah. You are right.
First time. It failed with double quote, I thought () could be the problem,
that's why I added %bquote, thought it would help.
Now it works with "", however still no clue why informat=$50. changed to
informat=,

select
information

【在 s******y 的大作中提到】
: 还有2场。 下下星期的风险较高, 当然回报也高。 我是想all-in。 然后征些包子赌
: 第二场。 不然我早睡觉去了。不建议你参与这两次。 血本乌龟的可能性太高

s******r
发帖数: 1524
11
it is not what I want to do.
What I want to do is to create a report based on a table contents.
like how many record with c=3 or ( a>=1 and b>=2 )
how many c=3 or (a>=2 and b>=1)

is

【在 s******y 的大作中提到】
: To your question. yes, it is:
: option validvarname=any;
: data a;
: 'and (a>=1 and b>=2)'n='hello alex';
: run;
: proc contents;
: run;
: but I don't think OP wants to add a column with that name. my best guess is
: OP want to pass a condition dynamically to somewhere.
: BAOZI please!

s******y
发帖数: 352
12
can you do something like this:
select sum(c=3 or ( a>=1 and b>=2 )) as condtion1,
sum(c=3 or (a>=2 and b>=1)) as condition2,...
from connect to sql ................

【在 s******r 的大作中提到】
: it is not what I want to do.
: What I want to do is to create a report based on a table contents.
: like how many record with c=3 or ( a>=1 and b>=2 )
: how many c=3 or (a>=2 and b>=1)
:
: is

s******r
发帖数: 1524
13
It will be slow. I try to transfer minimum data from database.

【在 s******y 的大作中提到】
: can you do something like this:
: select sum(c=3 or ( a>=1 and b>=2 )) as condtion1,
: sum(c=3 or (a>=2 and b>=1)) as condition2,...
: from connect to sql ................

1 (共1页)
进入Statistics版参与讨论
相关主题
请教sas高人(数据读入)SAS菜鸟请教substr
在R里如何连接一个字符变量和一个字符?sas一问
ASK FOR ONE SAS QUESTION怎样在data step跳过格式不对的data record?
请问:SAS如何生成这三个DATA SETS (DATA STEP SELECT STATEMENT)SAS9.2 - Z format
sas questionSAS Base 123题中47和112题疑问
一个sas问题What is wrong with this?
有关sas macro 的问题Help: an I/O ERROR occured
Help needed! What sas function can read char. date HH:DD:SS:SSS to numeric?怎么去掉一个CHARACTER VAR中的delimiters
相关话题的讨论汇总
话题: select话题: informat话题: sql话题: error话题: bquote