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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 813 views
  • 1 like
  • 2 in conversation