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;
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.
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!
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.
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;
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.
Thanks Reeza, I misclicked. I will follow your advice to use proc append instead.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.