BookmarkSubscribeRSS Feed
etl_tool
Calcite | Level 5

I'm trying to send out ID's of 2 SAS datasets which has ID's that were transferred and ID's that failed to transfer in an email body as text but not able to get the format right. I just need plain text as html is getting stuck and slow.  Here is my current code but the ID's are missing after it reaches 32000.. I saw CATX takes only that but also when it is called through Macro it can take 64000 but since I'm new to SAS I'm not sure how to do it.

Please help and also let me know how to add the SAS dataset of ID's that were not processed after the text of ID's processed.

%include '/saswrk/go/scripts/envsetup.sas';

filename mymail email
"&emaillist"
  subject
= "&env. Records Transferred on %sysfunc(date(), yymmdd10.)";

data _null_
;
  length id_list
$ 3000;
  retain id_list
'';

  
set workgo.recds_processed nobs = nobs end = eof;
  
file mymail;

  
if _n_ = 1 then do;
  put
'Number of records processed=' nobs;
  put
'The IDs are:';
  
end;

  
/* Print the IDs in chunks */
  
if length(strip(id_list)) > 2000 then do;
  put id_list
;
  call missing
(id_list);
  
end;

  call catx
(', ', id_list, id);

  
if eof then put id_list;
run
;

1 REPLY 1
hbi
Quartz | Level 8 hbi
Quartz | Level 8

Something like this should work. It was unclear from your example what filtering criteria should be used for good IDs (that transferred) and bad IDs (that did not transfer), so this example is generic. 

 

PROC SQL;
  SELECT DISTINCT id 
  INTO :good_id_list SEPARATED BY ", "
  FROM work.my_dataset1
  WHERE /* add filtering criteria for IDs that are good (transferred) */
  ;
QUIT;


PROC SQL;
  SELECT DISTINCT id 
  INTO :bad_id_list SEPARATED BY ", "
  FROM work.my_dataset2
  WHERE /* add filtering criteria for IDs that are bad (did not transfer) */
  ;
QUIT;


DATA _null_;
  file sendit email
    from="your_name@name_of_company.com"
    to=("recipient_name@name_of_company.com")
    cc=("courtesy_copy_name1@name_of_company.com"
        "courtesy_copy_name2@name_of_company.com"
        "courtesy_copy_name3@name_of_company.com")
    subject="&env. Records Transferred on %sysfunc(date(), yymmdd10.)"
    importance="High";

  if length(&bad_id_list) > 65500 then do;
    put "BEWARE: macro variable 'bad_id_list' exceeds maximum length of 64 kilobytes.";
    put "The list of IDs have been truncated.";
  end;
  if length(&good_id_list) > 65500 then do;
    put "BEWARE: macro variable 'good_id_list' exceeds maximum length of 64 kilobytes";
    put "The list of IDs have been truncated.";
  end;

  put "Below is a list of IDs that transfered:";
  put "=======================================";
  put &good_id_list;
  put "";
  put "";
  put "Below is a list of IDs that did not transfer:";
  put "=============================================";
  put &bad_id_list;
  put "";
  put "";
  put "Regards,";
  put "SAS guy";
  put;
RUN;

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
  • 634 views
  • 0 likes
  • 2 in conversation