BookmarkSubscribeRSS Feed
01SASUser
Fluorite | Level 6

Hello. May I know how to convert my comment (/*         */) into SAS code? Thanks.

%macro loop;

proc sql;

select max(tnx_dt) into: today from TESTING;

quit;

%DO k= %sysevalf("&today"d) %TO  %eval(%sysfunc(today())-2);

proc sql;

select max(tnx_dt) into: today1 from TESTING;

select max(tnx_dt-1) into: yesterday from TESTING;

select max(tnx_dt+1) into: tomorrow from TESTING;

quit;

%let day = %substr(&today1,1,5);

%let dt1 = %substr(&yesterday,1,9);

%let dt2 = %substr(&tomorrow,1,9); 

            /*IF TABLE_RAW_DATA EXISTS, DO THE CODE BELOW */    

            proc sql;

            insert into TESTING values("&dt2"d);

            quit;

            /*ELSE IF TABLE_RAW_DATA DOES NOT EXISTS, DO THE CODE BELOW*/

            proc sql;

            insert into TESTING (tnx_dt)

            select tnx_dt from previous_data;

            quit;

%end;

%mend;

%loop;

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

Probably the easiest way is to use the exist() function, e.g:

%if %sysfunc(exist(WORK.TABLE_RAW_DATA)) %then %do;

You could also query the sashelp.vtable dataset.

Alternatively,, drop the whole macro concept and generate the SAS code from a data _null_; call execute.

01SASUser
Fluorite | Level 6

Hello. Thank you for the response.

What if the conditions are:

- IF TABLE_RAW_DATA1 AND TABLE_RAW_DATA2 AND TABLE_RAW_DATA3 EXISTS

- ELSE IF ((TABLE_RAW_DATA1 AND TABLE_RAW_DATA2 EXISTS) AND (TABLE_RAW_DATA3 DOES NOT EXISTS))

May I know how to convert it into SAS code?

Kurt_Bremser
Super User

Once your conditions get complicated, I recommend doing them in a data _null_ step and put the result into a macro variable with call symput('cond_var','Y') or call symput('cond_var','N'), respectively. That way you can easily check if it works by simply doing a %put &cond_var after the data _null_ step.

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