Hi,
I have the following macro code below. An error message was shown in the log window when it ran. Could a data line step be run in Macro Macro steps? Please help.
%macro AriINPChart;
proc sort data=icd_10_cm_b; by icd_10_cm; run;
data icd_10_cm; set icd_10_cm_a icd_10_cm_b; run;
proc sort data=icd_10_cm nodupkey; by icd_10_cm; run;
data Valid_ICD;
LENGTH icd_10_cm $ 10;
input icd_10_cm $;
infile datalines delimiter="/";
datalines;
H669/
0219/
D59219/
Z283/
M545/
R05/
J899/
Y938/
Z20882/
;
run;
proc sort data=Valid_ICD; by icd_10_cm; run;
%macro vvv(ooo);
%do ooo=1 %to 10;
%let i=(&rr + 1);
%let rr=%eval(&i);
data inptadmitdx&ooo;
set ds2inp (keep=studysite scrdate caseid inptadmitdt inptdischargedt inptadmitdx&ooo);
if inptadmitdx&ooo ne ' ';
if inptadmitdx&ooo in('999.9999','999..999','999.999','U07.1','U07.0','R51','M35.8') then delete;
icd_10_cm=upcase(compress(inptadmitdx&ooo,',.[]-/'));
run;
proc sort data=inptadmitdx&ooo; by icd_10_cm; run;
data inpcr&rr (keep=studysite scrdate caseid inptadmitdt inptdischargedt inptadmitdx&ooo icd_10_cm);
merge inptadmitdx&ooo (in=a) icd_10_cm (in=b) Valid_ICD (in=c);
by icd_10_cm;
if a=1 and b ne 1 and c ne 1;
run;
proc sort data=inpcr&rr; by studysite caseid; run;
%let inp_&rr.a=%str(Admission diagnosis [inptadmitdx&ooo.] does not match ICD-10-CM code list);
ods proclabel "Check &rr:&&inp_&rr.a";
data inpcr&rr;
set inpcr&rr;
if caseid in ('EH1R09895') then delete;
var1='scrdate='||trim(left(put(scrdate,mmddyy10.)))
||', '||"inptadmitdt="||trim(left(put(inptadmitdt,mmddyy10.)))
||', '||"inptdischargedt="||trim(left(put(inptdischargedt,mmddyy10.)))
||', '||"inptadmitdx&ooo.="||trim(left(put(inptadmitdx&ooo,$20.)));
||', '||"inptadmitdx&ooo. without special symbol="||trim(left(put(icd_10_cm,$20.)));
format studysite studysite.;
run;
%createinp;
%end;
%mend vvv;
%vvv;
%mend AriINPChart;
%AriINPChart;
MPRINT(ARIINPCHART): data Valid_ICD; MPRINT(ARIINPCHART): LENGTH icd_10_cm $ 10; MPRINT(ARIINPCHART): input icd_10_cm $; MPRINT(ARIINPCHART): infile datalines delimiter="/"; MPRINT(ARIINPCHART): datalines; ERROR: The macro ARIINPCHART generated CARDS (data lines) for the DATA step, which could cause incorrect results. The DATA step and the macro will stop executing. NOTE: The data set WORK.VALID_ICD has 0 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds MPRINT(ARIINPCHART): ; MPRINT(ARIINPCHART): ; MPRINT(ARIINPCHART): ; MPRINT(ARIINPCHART): ; ERROR: The macro ARIINPCHART will stop executing. 2165
DATALINES (or CARDS or similar) is not supported in SAS macro. One workaround is to write this data to a file outside of the macro, and then make that file available to the macro during its execution and reference with INFILE. Others here might have more suggestions.
DATALINES (or CARDS or similar) is not supported in SAS macro. One workaround is to write this data to a file outside of the macro, and then make that file available to the macro during its execution and reference with INFILE. Others here might have more suggestions.
@ChrisHemedinger is right. But looking at this part of the code:
proc sort data=icd_10_cm_b; by icd_10_cm; run;
data icd_10_cm; set icd_10_cm_a icd_10_cm_b; run;
proc sort data=icd_10_cm nodupkey; by icd_10_cm; run;
data Valid_ICD;
LENGTH icd_10_cm $ 10;
input icd_10_cm $;
infile datalines delimiter="/";
datalines;
H669/
0219/
D59219/
Z283/
M545/
R05/
J899/
Y938/
Z20882/
;
run;
proc sort data=Valid_ICD; by icd_10_cm; run;
There's no reason for any of this to be inside a macro.
You can also put your data inside an external text file or external CSV file, and read it in from the external file, that should work inside a macro.
DATALINES cannot be used in a macro, and macro triggers are not recognized in a DATALINES block. Run the DATA step with the DATALINES outside of the macro.
You cannot use in-line data inside a macro. Once the macro is compiled the "lines" would be gone any way.
Your example dataset is trivial to create without in-line data.
data Valid_ICD;
LENGTH icd_10_cm $10;
do icd_10_cm =
'H669'
,'0219'
,'D59219'
,'Z283'
,'M545'
,'R05'
,'J899'
,'Y938'
,'Z20882'
;
output;
end;
run;
Another solution if you need to use the DATALINES statement in a macro call is to put the datastep code in a separate SAS file, and then just %INCLUDE it from the macro
%macro AriINPChart;
proc sort data=icd_10_cm_b; by icd_10_cm; run;
data icd_10_cm; set icd_10_cm_a icd_10_cm_b; run;
proc sort data=icd_10_cm nodupkey; by icd_10_cm; run;
%include 'c:\datastep.sas';
- you probably want another path for the datastep code, but that's the idea.
Just to have the full answer, here is "why?" https://support.sas.com/kb/43/902.html
Bart
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.