简体   繁体   中英

SAS Contains All Code

There's a big data download to do using 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.

A colleague informed me that in SQL you can use an * (asterisk) to include every customer number.

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.

Thanks

Generate different where clause based on whether the list of customer numbers is empty or not. 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.

If you are not using a macro you can use IFC() function to generate your where clause conditionally

%*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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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