DATA Step, Macro, Functions and more

Conditionally create unique index

Accepted Solution Solved
Reply
Regular Contributor
Posts: 212
Accepted Solution

Conditionally create unique index

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;


Accepted Solutions
Solution
‎04-04-2016 05:52 PM
Super User
Posts: 10,473

Re: Conditionally create unique index

[ Edited ]

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.

View solution in original post


All Replies
Solution
‎04-04-2016 05:52 PM
Super User
Posts: 10,473

Re: Conditionally create unique index

[ Edited ]

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.

Regular Contributor
Posts: 212

Re: Conditionally create unique index

Thanks so much for the help. I appreciate it.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 199 views
  • 2 likes
  • 2 in conversation