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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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