简体   繁体   English

SAS包含所有代码

[英]SAS Contains All Code

There's a big data download to do using SAS (Proc SQL). 使用SAS(Proc SQL)需要下载大量数据。

Sometimes I require to look at a particular customer number, or a couple customer numbers and equally often will require every customer number. 有时我需要查看一个特定的客户编号,或者几个客户编号,并且同样经常需要每个客户编号。

I would like to set up a macro variable so that the user can enter in either the customer numbers they require, or can enter some short version which will include everything. 我想设置一个宏变量,以便用户可以输入所需的客户编号,也可以输入将包含所有内容的简短版本。

ie %Let dCustomer_Number = in (3123, 1234) where &dCustomer_Number would be in the WHERE section of the query. 即%Let dCustomer_Number = in(3123,1234),其中&dCustomer_Number将在查询的WHERE部分中。

A colleague informed me that in SQL you can use an * (asterisk) to include every customer number. 一位同事告诉我,在SQL中,您可以使用*(星号)包括每个客户编号。

The closest I have come across is like '%' but this does not seem to work for numeric variables. 我遇到的最接近的符号是'%',但这似乎不适用于数字变量。 Is there something similar which will work? 是否有类似的东西会起作用?

I know it could be easy enough to just delete the where statement for the customer number filter but I don't want the user to have to actually alter the code, only the macro variables at the start. 我知道仅删除客户编号过滤器的where语句可能很容易,但是我不希望用户实际上必须更改代码,而只是在开始时更改宏变量。

Thanks 谢谢

Generate different where clause based on whether the list of customer numbers is empty or not. 根据客户编号列表是否为空生成不同的where子句。 Normally you can use an obviously true expression, such as 1=1 , to add to your WHERE clause so that your full statement syntax doesn't change. 通常,您可以使用明显为true的表达式(例如1=1 )将其添加到WHERE子句中,以使完整的语句语法不变。

If you are not using a macro you can use IFC() function to generate your where clause conditionally 如果不使用宏,则可以使用IFC()函数有条件地生成where子句

%*let dCustomer_Number = 3123,1234 ;
%let dCustomer_Number = ;
%let where_clause = %sysfunc(ifc
   (%length(&dCustomer_Number)
  ,(Customer_Number in (&dCustomer_Number))
  ,(1=1)
));
...
where &where_clause;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM