BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fbl204653
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

6 REPLIES 6
Reeza
Super User
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;
fbl204653
Obsidian | Level 7

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!

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

fbl204653
Obsidian | Level 7

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;

 

Reeza
Super User

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.

fbl204653
Obsidian | Level 7

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 1152 views
  • 2 likes
  • 3 in conversation