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

I have a daily process with a some user defined variables that are set, each day by the user before processing. 

 

2 Questions:

1.  I have a query / Proc SQL statement within the processes that I want to run only on Settlement day

 

How could I do this?

 

%Let Settle_DAY_Y_N = "YES"

If  &Settle_DAY_Y_N. = "YES" Then    /*  This is the condition */

Proc SQL;

/*Run SQL here */

/*  Settlement update query here */

run;

 

else

/* Don't Run SQL here */

end;

 

2.  (2nd Question) Would your solution also works for this?

 

%Let Settle_DAY_Y_N = "YES"

 

If  &Settle_DAY_Y_N. = "YES" Then   /*  This is the condition */

 

Data work.Combine_Records;

set work.A work.AA work.AAA;

run;

 

else

Data work.Combine_Records;

set work.A work.AA;   /* Since no settlement record was created drop work.AAA */

run;

end;

 

Many Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You can do it by using macro program. Pay attention to syntax:

 

%macro doit(Settle_DAY_Y_N); 

        %If  &Settle_DAY_Y_N. = YES %Then %do;      /*  This is the condition */

              Proc SQL;

               /*Run SQL here */

              /*  Settlement update query here */

             run;

       %end;

%mend doit;

%doit;

 

You can enter any sas code between %do;  and  %end;

 

  

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18

You can do it by using macro program. Pay attention to syntax:

 

%macro doit(Settle_DAY_Y_N); 

        %If  &Settle_DAY_Y_N. = YES %Then %do;      /*  This is the condition */

              Proc SQL;

               /*Run SQL here */

              /*  Settlement update query here */

             run;

       %end;

%mend doit;

%doit;

 

You can enter any sas code between %do;  and  %end;

 

  

Kody_devl
Quartz | Level 8

Shmuel,

 

Thank you very much1

 

Perfect!

 

Kody_Devl

Kody_devl
Quartz | Level 8

Shmuel,

 

My version is not evaluating correcly as "YES" (Skips my code) and is probably syntax.  Do you see it?

 

 

%Let Settle_Today_Y_N = 'YES'; /* CAPS YES or NO */

 

%macro Settled(Settle_Today_Y_N);

%If &Settle_Today_Y_N. = 'YES' %Then %do;

proc import datafile = "/sas/sasperm3_prod/yyyyyyy/xxxx/import/&Settled."

out= A_SRC_Settled dbms= xlsx replace;

getnames= yes;

range= 'Settled';

run;

%end;

%mend Settled;

%Settled;

 

Shmuel
Garnet | Level 18

You should define the macro variable either by %LET - then define %MACRO DOIT().

or define the macro variable as an argumnet to the macro program, the way I wrote it:

      %macro doit(Settle_Today_Y_N);   /* just define name to argument)

          ... 

      %mend doit;

      %doit('YES');     /* asign value to argument */

 

But, when you use macro variable you don't need quotes:

       either define %let Settle_Today_Y_N = YES;

       or  define     %doit(YES);

       then check by:   %if &Settle_Today_Y_N = YES %then ...   /* YES without quotes */

 

 

ballardw
Super User

And

%else %do;

  <other code>

%end;

 

Macro %if or %do require the code be inside a macro definition %macro/%mend construct to define and the call the macro. Otherwise use of %if or %do will generate error messages of  attempting to use in open code.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 4422 views
  • 0 likes
  • 3 in conversation