BookmarkSubscribeRSS Feed
Pavan_SAS
SAS Employee
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
9 REPLIES 9
Pavan_SAS
SAS Employee
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
Pavan_SAS
SAS Employee
s i know that !

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

macro can't process cards;
?
?
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Pavan_SAS
SAS Employee
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
Pavan_SAS
SAS Employee
"since CARDS cannot be used in macro because physical
lines are not respected by macro."
Peter_C
Rhodochrosite | Level 12
"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
john_sanzone
Calcite | Level 5
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
JLD
SAS Employee JLD
SAS Employee

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.

SAS Innovate 2025: Register Now

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!

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
  • 9 replies
  • 14864 views
  • 4 likes
  • 5 in conversation