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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

 

 

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

 

 

jklaverstijn
Rhodochrosite | Level 12

@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.

buechler66
Barite | Level 11
Thank you. I appreciate your time.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 781 views
  • 2 likes
  • 3 in conversation