I'm trying to send out ID's of a SAS dataset in an email but not able to get the format right. I just need plain text as html is getting stuck and slow. Thanks in advance to help! Any one solution would be good.
I have one ID column. The first solution one gives a complete list like
%include "/saswrk/go/scripts/envsetup.sas";
filename mymail email "&emaillist."
subject=" &env. Records Transferred on %sysfunc(date(),yymmdd10.)";
data null;
set WORKGO.recds_processed;
file mymail;
put (_all_)(=);
run; quit;
Output
ID=1
ID=2
ID=3
ID=4
ID=5
It would be nice if i could get the count and output like
Number of records processed=6 and the ID's are 1,2,3...
Try this:
%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;
At the first iteration of the data step, when _n_ = 1
, the number of observations in the dataset is written to the file.
Then, at each iteration, the current ID is appended to a comma-separated list of IDs. When the length of the list exceeds 2,000, the contents of the list is printed and the list is reset to empty. This ensures that the maximum length of a SAS character string is never reached, thereby avoiding errors.
When the end of the input dataset is reached, the current contents of the list is output.
This will give you multiple chunks of comma-delimited IDs where each chunk is separated by a newline.
To append the IDs from a second dataset you can simply modify the existing file using the mod
keyword in the file
statement and write the observations in an otherwise identical manner.
data _null_;
length id_list $ 3000;
retain id_list '';
set workgo.recds_not_processed nobs = nobs end = eof;
file mymail mod;
if _n_ = 1 then do;
put 'Number of records not 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;