DATA Step, Macro, Functions and more

why cards statement inside a macro program generating error message?

Reply
SAS Employee
Posts: 73

why cards statement inside a macro program generating error message?

means, y we are not able to create new sas dataset inside a macro program with cards statement (instream data)? Message was edited by: sas-r&d
SAS Employee
Posts: 73

Re: why cards statement inside a macro program generating error message?

Posted in reply to Pavan_SAS
example is:

%macro test;

data temp;
input id name $;
cards;
1 pavan
2 ramu
3 john
;
run;

%mend test;
%test;

log is:

ERROR: The macro TEST 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.TEMP has 0 observations and 2 variables.
NOTE: DATA statement used:
real time 0.28 seconds
cpu time 0.06 seconds


ERROR: The macro TEST will stop executing.
Super Contributor
Super Contributor
Posts: 3,174

Re: why cards statement inside a macro program generating error message?

Posted in reply to Pavan_SAS
From the SAS support http://support.sas/com/ the MACRO language documentation mentions this constraint. You will need to separate the DATA step code portion from your external (DATALINES or CARDS) input handling, since that portion cannot be interpreted by the macro compiler.

Scott Barry
SBBWorks, Inc.

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/macro-stmt.htm
SAS Employee
Posts: 73

Re: why cards statement inside a macro program generating error message?

s i know that !

but i am looking for the reason?
why?
why?

macro can't process cards;
?
?
Super Contributor
Super Contributor
Posts: 3,174

Re: why cards statement inside a macro program generating error message?

Posted in reply to Pavan_SAS
Good grief - because SAS is designed that way, with such a limitation.

But if you are really looking for an answer, such as to the question "why is the moon not round every night?", then I suppose you could open a SAS support track and ponder your curiosity a while, otherwise you may just want to accept the limitation and take an alternative coding approach.

Scott Barry
SBBWorks, Inc.
SAS Employee
Posts: 73

Re: why cards statement inside a macro program generating error message?

s, i know that !

but v r not kids just to follow what ever has written in text books and complete the exam !
v need to think beyond !
if there is one limitation, there must be one reason which caused for that limitation.

i will let u know the reason soon !

there is a reason for "why is the moon not round every night?" Message was edited by: sas-r&d
SAS Employee
Posts: 73

Re: why cards statement inside a macro program generating error message?

Posted in reply to Pavan_SAS
"since CARDS cannot be used in macro because physical
lines are not respected by macro."
Valued Guide
Posts: 2,177

Re: why cards statement inside a macro program generating error message?

Posted in reply to Pavan_SAS
"in my opinion"

macros package processing
datalines or cards are ad-hoc (data in syntax!)

I see these facilities serving different problem situations

Serving both situations, you could use a macro which stops just before the data lines. I believe you should be able to find a paper presented at SUGI which does and demonstrates the convenience ~ a bit like zOS JCL feature "instream data"

good luck Pavan
and keep thinking of the concepts behind the rules

PeterC
New Contributor
Posts: 2

Re: why cards statement inside a macro program generating error message?

Pavan,

I too recently encountered the problem of not being able to use cards/datalines within a macro setting and a quick search on this forum surfaced your plight as well. another alternative for you would be to stage the SAS code used in creating the data set via cards/datalines in another file and then use the %include to call it in at the appropriate time, even using %include within the macro statement -- it's not a problem. Again, offered as a workaround, but not happy with the initial shock over not being able to use datalines as I originally thought within a macro....

Good luck!
John
SAS Employee JLD
SAS Employee
Posts: 2

Re: why cards statement inside a macro program generating error message?

Posted in reply to Pavan_SAS

A little bit late ---- This is answered in SAS Note  43902 : http://support.sas.com/kb/43/902.html

Most of the SAS Language and all of the SAS Macro Language are 'free format' giving the ability to format and indent code for better readability. When compiling a macro, the SAS Macro Facility strips out any formatting (spaces, line breaks, tabs, etc.) in the model text to minimize the size of the stored text.

DATALINES, CARDS, and PARMCARDS statements are not free format. When the SAS Macro Facility compiles these statements, it removes the formatting, which would very possibly move data into incorrect lines and/or columns. This can cause incorrect results and is the fundamental reason for the restriction.

Ask a Question
Discussion stats
  • 9 replies
  • 7275 views
  • 2 likes
  • 5 in conversation