Help using Base SAS procedures

Comparison failing in if else when used with system parameters used

Reply
Occasional Contributor
Posts: 5

Comparison failing in if else when used with system parameters used

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

Super Contributor
Posts: 345

Re: Comparison failing in if else when used with system parameters used

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."

;

Super Contributor
Posts: 349

Re: Comparison failing in if else when used with system parameters used

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

Contributor
Posts: 52

Re: Comparison failing in if else when used with system parameters used

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.

Ask a Question
Discussion stats
  • 3 replies
  • 158 views
  • 3 likes
  • 4 in conversation