BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

6 REPLIES 6
ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Kurt_Bremser
Super User

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.

Tom
Super User Tom
Super User

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;
s_lassen
Meteorite | Level 14

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. 

 

yabwon
Onyx | Level 15

Just to have the full answer, here is "why?" https://support.sas.com/kb/43/902.html

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-white.png

Missed SAS Innovate in Orlando?

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.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2100 views
  • 3 likes
  • 7 in conversation