I have a macro named CreateUniqueIndex. At a certain point in my program I invoke it using the call execute('%CreateUniqueIndex'). But I need to conditionally invoke it only when the index doesn't already existing. I've tried some examples our there, but the conditions seem to be ignored.
Can anyone help me on this?
* Build Unique Index ;
%macro CreateUniqueIndex;
PROC DATASETS;
MODIFY FinalData;
INDEX CREATE imb_code / UNIQUE NOMISS;
run;
%mend CreateUniqueIndex;
* Build unique index if not exist ;
DATA _NULL_;
call execute('%CreateUniqueIndex');
RUN;
Beside wondering about the need for a macro that has nothing but hardcoded values...
Does this look like of like what you need?
data _null_;
set sashelp.vmember (where=(Libname='WORK' and memname='FINALDATA'));
if upcase(index) = 'NO' then call execute('%CreateUniqueIndex');
RUN;
Assuming since your macro uses a single level dataset name and no explicit library that the data resides in the Work library.
This checks for the existance of any index. If the data set has an index defined using another variable then it will not create your new index.
Beside wondering about the need for a macro that has nothing but hardcoded values...
Does this look like of like what you need?
data _null_;
set sashelp.vmember (where=(Libname='WORK' and memname='FINALDATA'));
if upcase(index) = 'NO' then call execute('%CreateUniqueIndex');
RUN;
Assuming since your macro uses a single level dataset name and no explicit library that the data resides in the Work library.
This checks for the existance of any index. If the data set has an index defined using another variable then it will not create your new index.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.