BookmarkSubscribeRSS Feed
sas_Forum
Calcite | Level 5

data Test;
Input emilid$ sub$ cont$;
cards;
xyz@in.com  Rwaw1  Done
abc@in.com  Raw2  NOT
zxc@in.com  Raw3  what
run;

%MACRO testemail(pEmailid,pSubject,pContents);
  FILENAME mymail EMAIL "NULL"
  TO=("&pEmailid")
  SUBJECT="&pSubject";
   data _null_;
    FILE mymail;
       PUT "&pContents";
     
run;
%MEND;


proc sql;
select count(*) into :ph2cnt from test;
quit;

proc sql;
select SUBJECT into:sub  from test;
select BODY into:cont   from test;
select EMAIL_ID into:emilid from test;
quit;

%tempemail(EMAIL_ID,SUBJECT,BODY);

This was working and sending and taking only  first row

But what i want is to send this to the correspoding user based on that row.

Ex:
subject Raw1 and content Done should go to xyz@in.com 
subject Raw2 and content NOT should go to abc@in.com 
subject Raw3 and content what should go to zxc@in.com 


Input emilid$ sub$ cont$;
cards;
xyz@in.com  Rwaw1  Done
abc@in.com  Raw2  NOT
zxc@in.com  Raw3  what
run;

1 REPLY 1
Tom
Super User Tom
Super User

A couple of points about using SQL to generate macro variables from data.

1) You can select multiple fields (variables) in one query.  Separate the fields with commas and the list the target macro variables after the INTO also separated by commas. Note that the : is required for each target variable.

select SUBJECT

     , BODY

     , EMAIL_ID

  into :sub

      , :cont

      , emailid

  from test

;

2) You can select multiple rows (observations) in one query by adding the SEPARATED BY clause after the target macro variable name.

select SUBJECT

     , BODY

     , EMAIL_ID

  into :sub separated by '|'

     , :cont separated by '|'

     , emailid separated by '|'

  from test

;

But for you case why not just use the data step to generate the code. For example by using CALL EXECUTE to generating calls to your email macro:

data _null_;

   set list;

   call execute( '%testemail(' || catx(',',emailid,subj,cont) || ')' );

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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