0

i want to access char variable in where clause like below-->

%macro obs(indsn=, outdsn=, clause=, col=, optr=, subset_val=);

data &outdsn;
    set &indsn;
    &clause &col &optr &subset_val;
run;

proc print data= &outdsn;run;

%mend obs;

%obs(indsn=infos, outdsn=ch,clause=where,col=name,optr=?, subset_val=Namo);

am trying to incorporate "in contains like" operator in where clause but its not working gives syntax error... but missing eq ne le gt operators are working... how can I resolve this any help is appreciated.

  • welcome to stack overflow! Your question would be easier to answer if you could post an example (from the log) of the exact syntax error you are receiving.. – Allan Bowe Nov 03 '16 at 08:45

2 Answers2

1

You may be aiming for too much automation. Using the fact that WHERE can stand alone, I would suggest a modification as follows:

%macro obs(indsn=, outdsn=, filter=);

data &outdsn;
    set &indsn;;
    Where &filter;
run;

proc print data= &outdsn;run;

%mend obs;

%obs(indsn=infos, outdsn=ch, filter=name ? 'Namo');

If you end up with really complex filters that are having issues being parsed through you may need to mask the FILTER string

Reeza
  • 20,510
  • 4
  • 21
  • 38
  • 1
    I agree, I like passing the expression for the where clause in a single parameter, rather than using multiple parameters to pass different terms. I also like parameter names that are SAS key words, so I would parameterize this as `%obs(data=infos, out=ch, where= name ? 'Namo')`. – Quentin Nov 03 '16 at 12:59
0

Be sure to pass (quoted) literals where strings are required, eg as follows:

%obs(indsn=infos, outdsn=ch,clause=where,col=name,optr=?, subset_val='Namo');
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
  • your code IS pretty generic. I don't think you can really put the quotes in the datastep, as in some cases you may not want the quotes (eg numeric variables) or the quotes may be mixed (eg `where variable in ("don't",'the "don"','etc')` ) – Allan Bowe Nov 03 '16 at 09:05