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;
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.
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?
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.