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.

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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