BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
buechler66
Barite | Level 11

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
ballardw
Super User

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.

buechler66
Barite | Level 11
Thanks so much for the help. I appreciate it.
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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