Hi. I'm trying to conditionally create an index, but only if it doesn't already exist. Can anyone help me with this? This attempt isn't working for me.
data _null_;
set sashelp.vmember (where=(Libname='WORK' and memname='FINALDATA%unquote(&zip5)'));
if upcase(index) = 'NO' then do;
PROC DATASETS;
MODIFY FinalData%unquote(&zip5);
INDEX CREATE imb_code /unique;
end;
RUN;
Well, this will give you a start, but I don't know what that macro variable is or why it is there at all:
data _null_; set sashelp.vmember (where=(Libname='WORK' and memname='FINALDATA%unquote(&zip5)'));
if upcase(index)='NO' then call execute('proc datasets; modify finaldata'||&zip5.||'; index create imb_code /unique; run; quit;'); run;
Well, this will give you a start, but I don't know what that macro variable is or why it is there at all:
data _null_; set sashelp.vmember (where=(Libname='WORK' and memname='FINALDATA%unquote(&zip5)'));
if upcase(index)='NO' then call execute('proc datasets; modify finaldata'||&zip5.||'; index create imb_code /unique; run; quit;'); run;
@RW9 wrote:
data _null_; set sashelp.vmember (where=(Libname='WORK' and memname='FINALDATA%unquote(&zip5)'));
if upcase(index)='NO' then call execute('proc datasets; modify finaldata'||&zip5.||'; index create imb_code /unique; run; quit;'); run;
My 2 cents on this: this code will not create an index if any index exists. It is not specific to index imb_code. So there may still be room for improvement. But kudo's to the use of call execute(). Very underestimated and often misunderstood.
- Jan.
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.