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.

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!

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.

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