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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 10746 views
  • 7 likes
  • 3 in conversation