Hi,
I have some SAS code with a PROC SQL query in it, however I want to be able to pass in some variables and have a macro join them all together ready for the WHERE clause in my PROC SQL.
So far I have something like so:
%let claimant =%sysget(claimant);
%let policy_no =%sysget(policy_no);
%let soundex =1;
%let dob =%sysget(dob);
%let employer =%sysget(employer);
%let output_file =%sysget(output_file);
%macro query;
%global querystr;
%local comparison;
* Set comparison type ;
%if &soundex %then %let comparison=%str(=*);
%else %let comparison=%str(=);
* Insert policy number into final query ;
%if &policy_no %then %let querystr=;
%else %let querystr=%str(policy = &policy_no);
* Insert claimant into final query ;
%if &claimant %then ;
%else %let querystr=%str(&query_str AND claimany &comparison "&claimant"
* Insert dob into final query ;
%if &dob %then ;
%else %let querystr=%str(&query_str AND birth_dt = "&birth_dt"
* Insert employer into final query ;
%if &employer %then ;
%else %let querystr=%str(&query_str AND insured &comparison "&employer"
%mend;
%query;
The issues is of course :-
If one of the previous vars is not populated it will start with 'AND ...' the only way I can think of around this is a big ugly nested IF to check if any of the others had been used.
Has anyone else done this ?
Any examples of a better way to do this ?
Any suggestions on how I might go about it ?
Thanks,
Tim.
I have some SAS code with a PROC SQL query in it, however I want to be able to pass in some variables and have a macro join them all together ready for the WHERE clause in my PROC SQL.
So far I have something like so:
%let claimant =%sysget(claimant);
%let policy_no =%sysget(policy_no);
%let soundex =1;
%let dob =%sysget(dob);
%let employer =%sysget(employer);
%let output_file =%sysget(output_file);
%macro query;
%global querystr;
%local comparison;
* Set comparison type ;
%if &soundex %then %let comparison=%str(=*);
%else %let comparison=%str(=);
* Insert policy number into final query ;
%if &policy_no %then %let querystr=;
%else %let querystr=%str(policy = &policy_no);
* Insert claimant into final query ;
%if &claimant %then ;
%else %let querystr=%str(&query_str AND claimany &comparison "&claimant"
* Insert dob into final query ;
%if &dob %then ;
%else %let querystr=%str(&query_str AND birth_dt = "&birth_dt"
* Insert employer into final query ;
%if &employer %then ;
%else %let querystr=%str(&query_str AND insured &comparison "&employer"
%mend;
%query;
The issues is of course :-
If one of the previous vars is not populated it will start with 'AND ...' the only way I can think of around this is a big ugly nested IF to check if any of the others had been used.
Has anyone else done this ?
Any examples of a better way to do this ?
Any suggestions on how I might go about it ?
Thanks,
Tim.