The SAS Output Delivery System and reporting techniques

Adding Text in Proc Report

Frequent Contributor
Posts: 78

Adding Text in Proc Report

I have below code which generate an email and feed URL if it find's members in the PDS below:


Member name get created with Links ....

Now What I am trying to accomplish is along with the Member name I get some Text Feeded as weell against them...

So basically they look like as below :


ADPRATE   -  Adapter Data Rate

CHANNEL   - Channel Status

RMTTMNT   -  Mount Status

All above should be based on the Member name so basically I need to put something in the COMPUTE where it check IF FILE=ADPRATE then XXXX ....however this doesn't seems to work..anybody got any idea?? appreciated your help in advance..

Code :-

options errorabend mprint symbolgen mlogic
         nodate ps=max nocenter ls=255 ;
  %global memcount;
  %let memcount=&memcount;
  %macro memcheck(FILNAME);
  %* Check if PDS Contain any Members                               ;
   Data _null_ pdsmem;
     if check_rc=0    then
          Do ;
          call symput('memcount',left(put(memcount,5.)));
          put "number of members in pds is " memcount;
  %* If PDS Member count is 1 or greater than Open and list them    ;
    if memcount >= 1    then
        Do i = 1   to memcount ;
          file=dread(open_file,i) ;
   if fid > 0
     put file;
     output pdsmem;
        end ;
  %* If Any error message make sure to print it in the saslog       ;
    else  do;
    length msg $200.;
    msg = sysmsg();
    put msg=;
     end; run;
  %* Send Email                                                     ;
  ods listing close;
  ods noptitle;
  data _null_ ;
   %if  &memcount   >  0  %then %DO ;
  filename temp
           email to="XXXXX"
                      %*cc="XXXX" ;
                        subject="VTS Exception Report"
                        type="text/html"  ;
                      %*importance="high" ;

    ods listing close;
    ods noptitle;
    ods HTML4
    body=TEMP  ; %end;

    title 'VTS Consolidated Report for the Exceptions Found' ;
    proc report HEADLINE data=pdsmem nowd nocenter ;
    col  file ;
    define file / display 'Member'
    style={font_weight=bold background=yellow};
    compute file;
    LENGTH  text $ 50;
    urlstring =
    CALL DEFINE(_COL_,"URLBP",urlstring);
   %mend memcheck ;

Posts: 8,645

Re: Adding Text in Proc Report


  I am very confused by your code. Here are some questions/observations:

1) Do you know that the FILE variable is being created correctly in the DATA step program? How does FILE appear in the dataset WORK.PDSMEM? Why not add your extra text to the FILE variable in the DATA step program? For that matter, you could also build your URLSTRING in the DATA step program.

2) you have a LENGTH statement for the variable TEXT in your COMPUTE block, but you create a variable called URLSTRING -- from the variable FILE -- where did you intend to use TEXT? Does this code work?

3) What do you expect the HEADLINE option to do? -- it is ignored by ODS destinations.

4) You have your ODS HTML4 invocation *INSIDE* the %macro definition, but you have your CLOSE *OUTSIDE* of the %macro definition, after the %mend -- this may not be the right placement of your ODS HTML4 close.

5) In addition to having the ODS HTML4 close in the wrong place, you do not have a step boundary to end your PROC REPORT step.

6) Where/how do you INVOKE the macro program that you have defined? What error messages are you getting in the log? Personally, I would make sure that the HTML report is being created successfully, before I emailed it. I'm not convinced that you macro is working correctly and every time you test it, you have the potential to send an incorrect email to the recipients. For example, in my code below, I just create a simple HTML file so I can test the URL creation first. This is what I would recommend BEFORE you implement an email solution. Make sure your URL and addition of text works and then tackle the email issue.

7) Speaking of email, have you checked with your e-mail folks that you are allowed to send HTML mail? Some mail systems prohibit sending HTML mail and require that you send plain text mail. You may have to send your HTML file as an attachment instead of in the body of the email.

  Note in the code below, the 2 different ways to "add" text to a variable value -- one with IF statements and the other with PROC FORMAT. Note also that URLSTRING does NOT have to be created in the PROC REPORT step.


proc format;

  value $add 'Carol' = 'Burnett'

             'Jane'= 'Seymour, wife of Henry VIII'

             'Janet'= 'Evanovich bibliography'

             'Jeffrey'= 'Hunter on Star Trek'

             'John' = 'Steinbeck bibliography'

             'Joyce' = 'Carol Oates'

             'Judy' = 'Garland'

             'Louise'= 'Marley'

             'Mary' = 'Wollstonecraft Shelley'

             'Philip'= 'Roth bibliography'

             'Ronald'='McDonald House'

             'Robert' = 'Louis Stevenson'

             'Thomas' = 'the Tank Engine'

             'William' = 'the Conqueror';



data fromclass;

  length newname tempname $35 urlstring $100;

  set sashelp.class;

  if name = 'Alice' then newname = catx(' ',name,'In Wonderland');

  else if name = 'Barbara' then newname = catx(' ', name,'(Funny Girl) Streisand');

  else if name = 'Alfred' then newname = catx(' ',name,'What Me Worry');

  else if name = 'James' then newname = catx(' ',name,'Bond, 007');

  else if name = 'Henry' then newname = catx(' ',name,'Wadsworth Longfellow');

  else newname = catx(' ',name,put(name,$add.));

  tempname = urlencode(newname);

  put tempname=;

  urlstring = catt('',tempname);



ods _all_ close;

ods html4 path='c:\temp' (url=none) file='testurl.html';


proc report data=fromclass;

  column name urlstring newname;

  define name /display;

  define urlstring / noprint;

  define newname / display;

  compute newname;

    call define(_col_,'URL',urlstring);



ods html4 close;

Post a Question
Discussion Stats
  • 1 reply
  • 2 in conversation