BookmarkSubscribeRSS Feed
Jan_S
Calcite | Level 5

My requirement is to display the subject line as 'PROD' or 'TEST' in email based on the job name qualifier. i m getting the job name using &SYSJOBID variable. However on checking this in my sas program, the comparison fails. Below is my code:

data eg2;                        

%let trigtype="&SYSJOBID";       

%put trigtype;                   

%put &trigtype;                  

%put &trigtype.;                

/* trigtype got displayed as "AC11895K" in SASlog*/

%let sub1= "     ";              

if &SYSJOBID EQ "AC11895K"     

       THEN do;                  

       %let sub1="PROD";         

       end;                      

       else do;                  

       %let sub1="TEST";         

       end;                      

  run;           

FILENAME OUTBOX EMAIL                        

TO= ("XXXXXXXXXX")    

SUBJECT=&sub1.                              

-----

          

My jobname is AC11895K. But SAS sends mail with subject as 'TEST' since the else loop gets satisfied always. Could someone please help in resolving this issue?

Thanks,

Janet

3 REPLIES 3
andreas_lds
Jade | Level 19

An interesting mixture of macro and datastep code. You should spend some time reading the SAS 9.2 Macro Language: Reference (http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#titlepage.htm), especially the section "Understanding and Using the Macro Facility".


An untested idea:


data _null_; /* you don't need a dataset */

  if "&SysJobId" = "AC11895K" then call symputx("sub1"; "PROD");

  else call symputx("sub1", "TEST");

run

FILENAME OUTBOX EMAIL                        

TO= ("XXXXXXXXXX")    

SUBJECT="&sub1."

;

shivas
Pyrite | Level 9

Hi,

or you can write complete macro code...for eg

%macro test;

%let jobid=AC11895K;              

%let trigtype="&JOBID";             

%let sub1= "     ";             

%if "&JOBID" EQ "AC11895K"    

       %THEN %do;                 

       %let sub1="PROD";        

       %end;                     

       %else %do;                 

       %let sub1="TEST";        

       %end;                     

%mend test;

%test;

Thanks,

Shiva

tish
Calcite | Level 5

Oh. The reason the ELSE loop is satisfied in your code is that you have used the comparison

if &SYSJOBID EQ "AC11895K"

The macro variable &SYSJOBID does not contain a quoted value; your job ID really is AC11895K, right? So then the comparison fails because AC11895K does not equal "AC11895K"!

The comparison will work with either of the following (and maybe other forms, too):

%if &SYSJOBID =  AC11895K (in macro code)

     or

if "&SysJobId" = "AC11895K" (in data step code)


I hope this helps.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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