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

Hi,

 

I need to execute a SQL only if the name of a file contains the expression y0.

 

I tried it:

 

 

LIBNAME RECEITA BASE "G:\RECEITA";
IF instr(&Arq,"Y0.")>0 then call execute(
	"Proc sql;
	DELETE FROM RECEITA.ESTABELECIMENTOS;")
	RUN;

 

But  generats error:

 

team.png

 

How can I solve this?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Your IF statement must be in a DATA step. It will not work otherwise.

 

But you still have other problems preventing this from working. If your logic is to find the value "Y0." (that's three characters, a capital Y, a zero and a dot, in sequence) somewhere in variable &arq (but you haven't defined &arq), then you still have a problem that there is no INSTR function.

 

So, please, describe in words (not SAS code) exactly (and I mean in detail, step-by-step, leaving nothing out) what you are trying to do.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Your IF statement must be in a DATA step. It will not work otherwise.

 

But you still have other problems preventing this from working. If your logic is to find the value "Y0." (that's three characters, a capital Y, a zero and a dot, in sequence) somewhere in variable &arq (but you haven't defined &arq), then you still have a problem that there is no INSTR function.

 

So, please, describe in words (not SAS code) exactly (and I mean in detail, step-by-step, leaving nothing out) what you are trying to do.

--
Paige Miller
fabiopjr
Fluorite | Level 6

I need to use the "Replace" method when I'm going to read the first file, and the "Append to Existing" method in the others.

I had the idea to use "Append to Existing" and delete the table when I detected the reading of the first file. the code worked, however it had a problem with the table.

 

 

%macro APAGA;
/*proc sql;
	DELETE FROM RECEITA.ESTABELECIMENTOS;
	run;*/
	data RECEITA.ESTABELECIMENTOS;
	set RECEITA.ESTABELECIMENTOS (obs=0);
	run;
	
quit;

data _null_;
	IF instr(&Arq,"Y0.")>0 then call execute('%APAGA');
run;
quit;

 

 

 

I managed to solve it in another way, now I have two Jobs, one with the Append option and the other with Replace, I choose between one and the other in a third job.

 

 

 

 

My solution:

 

Untitled.png

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 382 views
  • 1 like
  • 2 in conversation