简体   繁体   English

如何修复SAS中的where子句

[英]How can I fix my where clause in SAS

I have a table is SAS say t looking like this 我有一个表是SAS说t这样看

A           B                   C       D
--------------------------------------------------------------
VOLUME      172631922966528     IMPLIED 2012-10-04
VOLUME      173731441803264     IMPLIED 2012-10-04
PRIX_VOLUME 189124634214400     IMPLIED 2012-10-04
PRIX_VOLUME 123153895784448     IMPLIED 2012-10-04
VOLUME      266090408574976     IMPLIED 2012-10-04
VOLUME      119855364243456     IMPLIED 2012-10-04

The column D is a Date (format yymmdd10 ) colume and I have a macrovarible date0 that is worth 2012-10-04 I am trying to do a trivial data-step D列是Date (格式yymmdd10 )列,并且我有一个值得2012-10-04的宏date0 ,我正在尝试执行一个简单的数据步骤

data test;
    set t (where=(A eq "VOLUME" and D eq &date0.));
run;

but this is not working 但这不起作用

Can you help fix it ? 你能帮忙解决吗?

That is because when the macro variable is processed, you get: 这是因为在处理宏变量时,您将获得:

data test;
    set t (where=(A eq "VOLUME" and D eq 2012-10-04));
run;

Which SAS will resolve as: data test; 哪种SAS可以解决:数据测试; set t (where=(A eq "VOLUME" and D eq 1998)); 设置t(其中=(Aeq“ VOLUME”和Deq 1998)); run; 跑; Because it sees math instead of a date. 因为它看到的是数学而不是日期。 You need to make clear to SAS that: 您需要向SAS明确说明:
1. it is not algebra. 1.不是代数。
2. it should read it as a date. 2.应该将其作为日期阅读。

To make it read it as a string, add quotes. 要使其以字符串形式读取,请添加引号。 To make clear that the string represents a date, append ad after the quotes: 为了使字符串表示日期,请在引号后附加广告:

data test;
    set t (where=(A eq "VOLUME" and D eq "&date0."d));
run;

That should do the trick. 这应该够了吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SAS如何在where子句中更改日期格式 - SAS how to change a date format in a where clause 如何在where子句中将日期转换为mm / dd / yyyy - How do i convert a date to mm/dd/yyyy in my where clause SAS - 如何读取日期数据? - SAS - how can I read in date data? 如何从 sql 中的日期中提取年份并将其用于 where 子句 - How I can extract year from a date in sql and use it in where clause SAS Proc SQL function 在 where 子句中仅适用于当前周 - SAS Proc SQL function in where clause for only current week 如何从SAS中的.csv文件中准确导入“日期”? - How can i accurately import “dates” from .csv files in SAS? 无论我在表中插入什么数据,日期都保持在 2022 年 1 月 3 日相同。 我怎样才能解决这个问题? - No matter what data I insert into my table, the date stays the same at 03.01.2022. How can I fix this? 在我的SQL where子句中需要动态日期 - Need dynamic dates in my SQL where clause 为什么当我在 WHERE 子句上使用我的属性时会出现转换失败错误,但当我不使用时它可以工作? - Why do I get a conversion failed error when I use my attribute on my WHERE clause but it works when I don't? 使用 VBA 中的 Range.Value 复制粘贴将我的文本格式化为日期。 我怎样才能解决这个问题? - Copy pasting using Range.Value in VBA formats my text as date. How can I fix this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM