I am using macro variable in datalines. I am getting error ERROR: The macro APPLYLOGIC generated CARDS (data lines) for the DATA step, which could cause incorrect results. The DATA step and the macro will stop executing. Please suggest me code where I can invoke macro variable in the datalines. The below code is for adding sample username to metadata in bulk. I can use the set statement and external file but for learning purpose I want to know function to use macro in datalines.
data employee;
length emailAddr $30. userid $30.;
input keyid$ name$ displayname$ emailAddr$ memkeyid$ userid$;
datalines;
P002 IBL11152 Atest1 email1@address P002 IBL\IBL11152
P003 IBL11153 Atest2 email2@address P003 IBL\IBL11153
P004 IBL11154 Atest3 email3@address P004 IBL\IBL11154
P005 IBL11155 Atest4 email4@address P005 IBL\IBL11155
P006 IBL11156 Atest5 email5@address P006 IBL\IBL11156
;
run;
%macro loopmacro;
%global keyidm namen displaynamem emailAddrm memkeyidm useridm lastrow;
data _null_;
set employee end=eof;
call symput('keyidm'||left(_n_),keyid);
call symput('namen'||left(_n_),name);
call symput('displaynamem'||left(_n_),displayname);
call symput('emailAddrm'||left(_n_),emailAddr);
call symput('memkeyidm'||left(_n_),memkeyid);
call symput('useridm'||left(_n_),userid);
if eof then call symput ('lastrow', left(_n_));
run;
%put &lastrow;
%mend;
%loopmacro;
%put &lastrow;
/* The meaning of canonical, if you are in doubt 🙂
"Conforming to orthodox or well-established rules or patterns, as of procedure."
*/
options symbolgen mprint mlogic;
/*--------------------------------------------------------
* Example based on MDUIMPC and MDUIMPL macros to import
* user info to the SAS Metadata Server.
*--------------------------------------------------------- */
/*--------------------------------------------------------
* FILL OUT INFO FOR METASERVER and METAUSER!!!!!!!!!
*----------------------------------------------------------*/
options metaserver= "*********" /*Your server Hostname */
metaport=8561
metauser="I*********""
metapass="*********""
metaprotocol=bridge
metarepository=Foundation;
/*
%MDUIMPC macro is used to define "canonical" tables and the data step is
used to extract data from external sources and append them to the tables.
*/
%mduimpc();
/* Create person table */
%macro applylogic;
%do i= 1 %to &lastrow;
data &persontbla ;
%definepersoncols;
infile datalines delimiter=',' missover;
input keyid name description title displayname;
datalines;
&&keyidm&i.,&&namen&i., ,CCBG,&&displaynamem&i.
;
run;
%end;
%mend;
%applylogic;
/*filename testxml 'filename.xml' lrecl=1024;*/
/*%mduimpl(outrequest=testxml);*/
%mduimpl();
Macro does not work in datalines. You would need to use the resolve() function for that. However I highly recommend you review your code/process and avoid using macro as much at possible. Most of that code is avoidable by dropping all the macro stuff and using Base Datastep. This alone:
%macro applylogic;
%do i= 1 %to &lastrow;
data &persontbla ;
Is resource heavy and verbose, all those datasets being created.
Macro does not work in datalines. You would need to use the resolve() function for that. However I highly recommend you review your code/process and avoid using macro as much at possible. Most of that code is avoidable by dropping all the macro stuff and using Base Datastep. This alone:
%macro applylogic;
%do i= 1 %to &lastrow;
data &persontbla ;
Is resource heavy and verbose, all those datasets being created.
What you're trying to do here is a nice example for how NOT to do it. You try to abuse the macro preprocessor for handling data, which results in convoluted and hard to create/maintain/understand code.
If you need to create code based on datasets, don't create lots of macro pseudo-arrays, use call execute() instead.
And the %mdu.... macros are pefectly good for handling multiple users in one step, so the creation of multiple datasets with one person each is nonsense.
A nice example for bulk import of users is found in SASHOME/SASFoundation/9.4/samples/base/importpw.sas. I use a slightly adapted version of this program for the automated synchronization of my operating system userbase with SAS metadata.
Hi,
The reason why macro facility does not accept datalines statements is explained in:
http://support.sas.com/kb/43/902.html
which is linked to in the below, which describes the use of the resolve() function mentioned by @RW9.
http://support.sas.com/kb/43/295.html
Regards,
Amir.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.