Hi, This is somewhat related to my previous post but the issue is different. Below is the macro I'm working with and some test code. When I run this code with the mprint option, out of a total of four vchk calls I can only see the following two mprint lines for vchk: MPRINT(VCHK): titi MPRINT(VCHK): , tata Both calls that deal with the non-existing toto variable don't generate any mprint line. I'm guessing it's because the macro has nothing to generate in these instances since the variable doesn't exist. I would like the macro to still generate an mprint line without interfering with any of the codes and I thought if a variable is missing then I could put a space instead. However, for some reason, I cannot have the macro put a simple blank space. It can put a non-break space, but that messes with the keep= code. Is there a way to have my macro put a space when a variable is missing? Or at least generate an mprint line anyway? Thanks! %macro vchk(in=,var=,lib=work,sql=0,alias=,xcpt=descending,noxist=0); %if 0<%length(&alias) %then %let alias=&alias..; %if &sql %then %let coma=%str(,); %else %let coma=; %let vchk_lst=; %let vchk_i=1; %do %while(%scan(&var,&vchk_i,%str( ))^= ); %let vchk_itm=%scan(&var,&vchk_i,%str( )); %if %length(&xcpt) and %upcase(&vchk_itm)^=%upcase(&xcpt) %then %do; %let vchk_dsid=%sysfunc(open(&lib..&in)); %let vchk_vnum=%sysfunc(varnum(&vchk_dsid,&vchk_itm)); %let vchk_dsid=%sysfunc(close(&vchk_dsid)); %if 0<&vchk_vnum and ^&noxist %then %let vchk_lst=&vchk_lst &coma &alias&vchk_itm; %else %if &vchk_vnum<1 and &noxist %then %let vchk_lst=&vchk_lst &coma &alias&vchk_itm; %end; %let vchk_i=%eval(&vchk_i + 1); %end; &vchk_lst %mend vchk; data titi1; titi=1; run; data titi2; titi=1; tata=1; run; data titi3; set titi1(keep=%vchk(in=titi1,var=titi) %vchk(in=titi1,var=toto)); run; proc sql; create table titi4 as select a.titi %vchk(in=titi1,var=toto,sql=1,alias=a) %vchk(in=titi2,var=tata,sql=1,alias=b) from titi1 as a left join titi2 as b on a.titi=b.titi; quit;
... View more