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

How can i use macro with if, else, end statement, if i want to just start sql if the condition is true.

 

I wanna just use if statement, so if today()= date column from my table, and if this is true, then run this sql:

 

create table work.filtered_data AS
select *
from xxx

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data _null_;
    set have;
    if date=today() then call symputx('start',1);
    else call symputx('start',0);
run;
%if &start=1 %then %do;
    proc sql;
         ...
    quit;
%end;

Works in SAS 9.4M5 and later.

--
Paige Miller

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

So you have a date variable in a dataset. Will this variable contain only a single distinct value in all observations, or different dates?

Pato485
Calcite | Level 5

just one, it is just one exact date in every month (but not same every month) when i need to start macro. But it is just one value in dataset everytime.

PaigeMiller
Diamond | Level 26
data _null_;
    set have;
    if date=today() then call symputx('start',1);
    else call symputx('start',0);
run;
%if &start=1 %then %do;
    proc sql;
         ...
    quit;
%end;

Works in SAS 9.4M5 and later.

--
Paige Miller
Pato485
Calcite | Level 5
Thanks for solution.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 968 views
  • 0 likes
  • 3 in conversation