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:
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 thefile
statement and write the observations in an otherwise identical manner.