BookmarkSubscribeRSS Feed
rkumar23
Calcite | Level 5

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

 

Member name get created with Links ....
ADPRATE
CHANNEL
RMTTMNT

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;
          Check_rc=filename("flref","&FILNAME");
     if check_rc=0    then
          Do ;
          Open_file=dopen("flref");
          memcount=dnum(open_file);
          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) ;
          fid=mopen(open_file,file);
   if fid > 0
   then
     put file;
     output pdsmem;
        end ;
        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" ;
                        REPLYTO="XXXX"
                        FROM="XXXXXX"
                        subject="VTS Exception Report"
                        type="text/html"  ;
                      %*importance="high" ;

    ods listing close;
    ods noptitle;
    ods HTML4
    Base="//XXXXXX"
    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 =
    "//XXXXXX"
     ||"("||trim(left(file))||")";
    CALL DEFINE(_COL_,"URLBP",urlstring);
    endcomp;
   %mend memcheck ;
   ODS HTML4 CLOSE ;


1 REPLY 1
Cynthia_sas
SAS Super FREQ


Hi:

  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.
       

Cynthia

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';

run;

 

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('http://www.google.com/#q=',tempname);

run;

 

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);

  endcomp;

run;

ods html4 close;

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!

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
  • 1 reply
  • 1727 views
  • 0 likes
  • 2 in conversation