I have a daily process with a some user defined variables that are set, each day by the user before processing.
2 Questions:
1. I have a query / Proc SQL statement within the processes that I want to run only on Settlement day.
How could I do this?
%Let Settle_DAY_Y_N = "YES"
If &Settle_DAY_Y_N. = "YES" Then /* This is the condition */
Proc SQL;
/*Run SQL here */
/* Settlement update query here */
run;
else
/* Don't Run SQL here */
end;
2. (2nd Question) Would your solution also works for this?
%Let Settle_DAY_Y_N = "YES"
If &Settle_DAY_Y_N. = "YES" Then /* This is the condition */
Data work.Combine_Records;
set work.A work.AA work.AAA;
run;
else
Data work.Combine_Records;
set work.A work.AA; /* Since no settlement record was created drop work.AAA */
run;
end;
Many Thanks
You can do it by using macro program. Pay attention to syntax:
%macro doit(Settle_DAY_Y_N);
%If &Settle_DAY_Y_N. = YES %Then %do; /* This is the condition */
Proc SQL;
/*Run SQL here */
/* Settlement update query here */
run;
%end;
%mend doit;
%doit;
You can enter any sas code between %do; and %end;
You can do it by using macro program. Pay attention to syntax:
%macro doit(Settle_DAY_Y_N);
%If &Settle_DAY_Y_N. = YES %Then %do; /* This is the condition */
Proc SQL;
/*Run SQL here */
/* Settlement update query here */
run;
%end;
%mend doit;
%doit;
You can enter any sas code between %do; and %end;
Shmuel,
Thank you very much1
Perfect!
Kody_Devl
Shmuel,
My version is not evaluating correcly as "YES" (Skips my code) and is probably syntax. Do you see it?
%Let Settle_Today_Y_N = 'YES'; /* CAPS YES or NO */
%macro Settled(Settle_Today_Y_N);
%If &Settle_Today_Y_N. = 'YES' %Then %do;
proc import datafile = "/sas/sasperm3_prod/yyyyyyy/xxxx/import/&Settled."
out= A_SRC_Settled dbms= xlsx replace;
getnames= yes;
range= 'Settled';
run;
%end;
%mend Settled;
%Settled;
You should define the macro variable either by %LET - then define %MACRO DOIT().
or define the macro variable as an argumnet to the macro program, the way I wrote it:
%macro doit(Settle_Today_Y_N); /* just define name to argument)
...
%mend doit;
%doit('YES'); /* asign value to argument */
But, when you use macro variable you don't need quotes:
either define %let Settle_Today_Y_N = YES;
or define %doit(YES);
then check by: %if &Settle_Today_Y_N = YES %then ... /* YES without quotes */
And
%else %do;
<other code>
%end;
Macro %if or %do require the code be inside a macro definition %macro/%mend construct to define and the call the macro. Otherwise use of %if or %do will generate error messages of attempting to use in open code.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.