DATA Step, Macro, Functions and more

Call execute

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Call execute

Hi SAS experts,

 

I have a question and thanks for your help in advance. 

 

I used the following macro and call execute to stack dates from a couple of dates, meanwhile, I wanted to add a variable containing the source of the dates using "var="&dtc.", but I failed. I got a message in log that 'var="||NAME||" where I actually wanted it to be equal to the name in alldtc data;' I've attached the snapshot for alldtc data. 

 

 

data dtc_p1;
run;

 

%macro dtcmap(in,dtc);
  data dtcmap;
  set ∈
  length dtc var $19.;
  dtc=substr(&dtc.,1,10);
  if dtc^='';

  var="&dtc.";
  keep usubjid dtc var;
  run;

 

  data dtc_p1;
  set dtc_p1
  dtcmap;
  run;
%mend dtcmap;

 

data _null_;
  set alldtc(where=(name not in ('SESTDTC' 'SEENDTC' 'DTHDTC')));
  call execute ("%dtcmap(ags307."||strip(memname)||","||NAME||")");
run;


Accepted Solutions
Solution
a month ago
Super User
Super User
Posts: 9,599

Re: Call execute

Posted in reply to fbl204653

I would suggest that this:

  call execute ("%dtcmap(ags307."||strip(memname)||","||NAME||")");

Is not a good idea.  Doube quotes invokes the macro processor, use single quotes:

  call execute (cats('%dtcmap(ags307.',memname,',',name,')'));

Note also I use cats(), this is simpler than two bars and strip as it automatically strips the data.

 

What is this code supposed to do?

data dtc_p1;
run;

Post something which we can actually run, or the log so we can see what is going on.  Post test data in the form of a datastep, not an office attachment.

View solution in original post


All Replies
Super User
Posts: 23,771

Re: Call execute

Posted in reply to fbl204653
dtc=substr(&dtc.,1,10); <- quote the DTC variable here since it's a string variable. You can also use SCAN() instead. If this doesn't fix it, please post your log from running the program with debugging options on.

options mprint symbolgen;
Contributor
Posts: 41

Re: Call execute

HI Reeza,

 

Thanks for your reply! I've attached three data sets that are needed for this macro, RS, PE and ALLDTC and the output data set DTC_P1. I just wanted the var to be 'RSDTC' when dates come from RS and var to be 'PEDTC' when dates from PE, but now it's "||NAME||". DTC column in DTC_p1 is exactly what I wanted.

 

Thanks!

Attachment
Solution
a month ago
Super User
Super User
Posts: 9,599

Re: Call execute

Posted in reply to fbl204653

I would suggest that this:

  call execute ("%dtcmap(ags307."||strip(memname)||","||NAME||")");

Is not a good idea.  Doube quotes invokes the macro processor, use single quotes:

  call execute (cats('%dtcmap(ags307.',memname,',',name,')'));

Note also I use cats(), this is simpler than two bars and strip as it automatically strips the data.

 

What is this code supposed to do?

data dtc_p1;
run;

Post something which we can actually run, or the log so we can see what is going on.  Post test data in the form of a datastep, not an office attachment.

Contributor
Posts: 41

Re: Call execute

Hi RW9,

 

Thanks for your suggestion! It works after I changed doube quotes to single quotes even though I'm still confused. Attached please find the snapshop of the output data. 

 

I used the following code to create a blank data set and stack new data with that. Is there a better solution?

 

data dtc_p1;
run;

 

Super User
Posts: 23,771

Re: Call execute

Posted in reply to fbl204653

PROC APPEND to append data is faster - it copies data in blocks, not one line at a time like a data step.

 

Please mark @RW9 solution as the answer, not your own post.

Contributor
Posts: 41

Re: Call execute

Thanks Reeza, I misclicked. I will follow your advice to use proc append instead.  

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 156 views
  • 2 likes
  • 3 in conversation