<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DATALINES statement inside a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37961#M7595</link>
    <description>Hi:&lt;BR /&gt;
  I can't find the exact reference in the doc, but the error message is quite clear:&lt;BR /&gt;
[pre]&lt;BR /&gt;
ERROR: The macro MONTHLY generated CARDS (data lines) for the DATA step, which could cause incorrect results.  &lt;BR /&gt;
The DATA step and the macro will stop executing.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                                                                      &lt;BR /&gt;
        &lt;BR /&gt;
  You could switch to a permanent flat file with your LOB and state info. You could use a user-defined format for this information. &lt;BR /&gt;
I don't understand why the read for LOBS data file is in the macro program ...does it change? If so, how were you going to update the section following the datalines. If the info is not going to change, then that's where I'd recommend just using a permanent text file or a permanent SAS dataset or a permanent user-defined format.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Fri, 08 Aug 2008 20:39:34 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2008-08-08T20:39:34Z</dc:date>
    <item>
      <title>DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37960#M7594</link>
      <description>Can anybody tell me why the following macro errors out:&lt;BR /&gt;
&lt;BR /&gt;
%macro monthly;&lt;BR /&gt;
        data lobs;&lt;BR /&gt;
            infile datalines;&lt;BR /&gt;
            input LOB $ STATE $;&lt;BR /&gt;
            datalines;&lt;BR /&gt;
               IMR IL&lt;BR /&gt;
               IMD IL&lt;BR /&gt;
               MMD MO&lt;BR /&gt;
               MMR MO&lt;BR /&gt;
               HMR IN&lt;BR /&gt;
               OMD OH&lt;BR /&gt;
               OAD OH&lt;BR /&gt;
            ;&lt;BR /&gt;
         run;&lt;BR /&gt;
 %mend;&lt;BR /&gt;
 %monthly;&lt;BR /&gt;
&lt;BR /&gt;
If the data step is run outside the macro it runs fine, once inside it errors. Is there a solution to this different from pulling the step out of the macro.&lt;BR /&gt;
&lt;BR /&gt;
Thank you.</description>
      <pubDate>Fri, 08 Aug 2008 19:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37960#M7594</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-08T19:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37961#M7595</link>
      <description>Hi:&lt;BR /&gt;
  I can't find the exact reference in the doc, but the error message is quite clear:&lt;BR /&gt;
[pre]&lt;BR /&gt;
ERROR: The macro MONTHLY generated CARDS (data lines) for the DATA step, which could cause incorrect results.  &lt;BR /&gt;
The DATA step and the macro will stop executing.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                                                                      &lt;BR /&gt;
        &lt;BR /&gt;
  You could switch to a permanent flat file with your LOB and state info. You could use a user-defined format for this information. &lt;BR /&gt;
I don't understand why the read for LOBS data file is in the macro program ...does it change? If so, how were you going to update the section following the datalines. If the info is not going to change, then that's where I'd recommend just using a permanent text file or a permanent SAS dataset or a permanent user-defined format.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 08 Aug 2008 20:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37961#M7595</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-08-08T20:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37962#M7596</link>
      <description>A macro definition must precede the invocation of that macro in your code. The %MACRO statement can appear anywhere in a SAS program, except within data lines. A macro definition cannot contain a CARDS statement, a DATALINES statement, a PARMCARDS statement, or data lines. Use an INFILE statement instead. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
regards,&lt;BR /&gt;
pavan.</description>
      <pubDate>Mon, 11 Aug 2008 08:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37962#M7596</guid>
      <dc:creator>Pavan_SAS</dc:creator>
      <dc:date>2008-08-11T08:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37963#M7597</link>
      <description>use this code:&lt;BR /&gt;
&lt;BR /&gt;
%macro monthly;&lt;BR /&gt;
&lt;BR /&gt;
data lobs;&lt;BR /&gt;
infile "C:\Documents and Settings\xisguest\Desktop\lobs.txt";&lt;BR /&gt;
input LOB $ STATE $;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%mend;&lt;BR /&gt;
%monthly;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
regards,&lt;BR /&gt;
Pavan.</description>
      <pubDate>Mon, 11 Aug 2008 08:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37963#M7597</guid>
      <dc:creator>Pavan_SAS</dc:creator>
      <dc:date>2008-08-11T08:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37964#M7598</link>
      <description>Thank you all for your answers.&lt;BR /&gt;
I was using the data step in a macro because the little data set needed to be created only if a condition was true, I do not need the data set otherwise. I do not see how a format will work on this case because I need to read every one of those lines and generate data form them. The external file is my only option and I did not wanted to go that way because I don't control the production environment and to deploy a simple file is a big head ache but it looks like that's my only option.</description>
      <pubDate>Tue, 12 Aug 2008 17:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37964#M7598</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-12T17:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37965#M7599</link>
      <description>Instead of an external file, why not do this instead?&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro monthly;&lt;BR /&gt;
data lobs;&lt;BR /&gt;
    array lobs{7} $3 _TEMPORARY_ ('IMR', 'IMD', 'MMD', 'MMR', 'HMR', 'OMD', 'OAD' );&lt;BR /&gt;
    array states{7} $2 _TEMPORARY_ ('IL', 'IL', 'MO', 'MO', 'IN', 'OH', 'OH' );&lt;BR /&gt;
    drop n;&lt;BR /&gt;
&lt;BR /&gt;
    do n = 1 to 7;&lt;BR /&gt;
        lob = lobs{n};&lt;BR /&gt;
        state = states{n};&lt;BR /&gt;
        output;&lt;BR /&gt;
    end;&lt;BR /&gt;
run;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%monthly;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 12 Aug 2008 18:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37965#M7599</guid>
      <dc:creator>Tim_SAS</dc:creator>
      <dc:date>2008-08-12T18:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37966#M7600</link>
      <description>hi pavan,&lt;BR /&gt;
have you checked the code submitted by u?&lt;BR /&gt;
people are talking something called macro,for your information,you can not make a macro simply by putting %macro.&lt;BR /&gt;
 i am sorry to tell u this you have to learn the basics of macro once again.</description>
      <pubDate>Tue, 19 Aug 2008 08:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37966#M7600</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-19T08:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37967#M7601</link>
      <description>hi whyel,&lt;BR /&gt;
&lt;BR /&gt;
i checked my code twice, before posting in forum.&lt;BR /&gt;
you are telling that "you can not make a macro simply by putting %macro."&lt;BR /&gt;
Then tell me, how we can make a macro?&lt;BR /&gt;
Plz explain. &lt;BR /&gt;
I want to learn that thing from you !&lt;BR /&gt;
&lt;BR /&gt;
we can use any macro variables also in a macro depending on our requirement:&lt;BR /&gt;
&lt;BR /&gt;
%macro monthly(table=);&lt;BR /&gt;
&lt;BR /&gt;
data &amp;amp;table;&lt;BR /&gt;
infile "C:\Documents and Settings\xisguest\Desktop\lobs.txt";&lt;BR /&gt;
input LOB $ STATE $;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%monthly(table=lobs);&lt;BR /&gt;
&lt;BR /&gt;
anyway, plz execute that code on your computer and reply me if there are any errors.&lt;BR /&gt;
plz check everything, before commenting anyone. :):)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
i know macros upto some extend.&lt;BR /&gt;
i think, i need not learn basics of macros once again !!!!!!!!!&lt;BR /&gt;
&lt;BR /&gt;
what i posted is the solution for AOrtega's problem.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
i got this log, after executing my code with sas9.2&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;1    %macro monthly;&lt;BR /&gt;
2&lt;BR /&gt;
3    data lobs;&lt;BR /&gt;
4    infile "C:\Documents and Settings\xisguest\Desktop\lobs.txt";&lt;BR /&gt;
5    input LOB $ STATE $;&lt;BR /&gt;
6    run;&lt;BR /&gt;
7&lt;BR /&gt;
8    %mend;&lt;BR /&gt;
9&lt;BR /&gt;
10   %monthly;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The infile "C:\Documents and Settings\xisguest\Desktop\lobs.txt" is:&lt;BR /&gt;
      File Name=C:\Documents and Settings\xisguest\Desktop\lobs.txt,&lt;BR /&gt;
      RECFM=V,LRECL=256&lt;BR /&gt;
&lt;BR /&gt;
NOTE: 7 records were read from the infile "C:\Documents and Settings\xisguest\Desktop\lobs.txt".&lt;BR /&gt;
      The minimum record length was 6.&lt;BR /&gt;
      The maximum record length was 6.&lt;BR /&gt;
NOTE: The data set WORK.LOBS has 7 observations and 2 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.04 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;/B&gt;</description>
      <pubDate>Wed, 20 Aug 2008 03:46:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37967#M7601</guid>
      <dc:creator>Pavan_SAS</dc:creator>
      <dc:date>2008-08-20T03:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37968#M7602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;* you write in a new sas file (let's say "data.sas") just your data step;&lt;/P&gt;&lt;P&gt;* then in your main sas file, where you make all manipulations you define a macro, for example;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&amp;nbsp; %macro example();&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if (your condition in macro language) %then %INCLUDE "C:\...\...\data.sas";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %mend();&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %example();&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;* it should work. i have tried it myself. of course nothing happens it the condition is not met.&lt;/P&gt;&lt;P&gt;* my full tryout code is:&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input abc;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select abc into :abc separated by ' ' from a;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;abc;&lt;/P&gt;&lt;P&gt;%macro example();&lt;/P&gt;&lt;P&gt;%if &amp;amp;abc&amp;lt;=3 %then %INCLUDE "U:\Diane\BODACC\proc_coll_me.sas";&lt;/P&gt;&lt;P&gt;%mend();&lt;/P&gt;&lt;P&gt;%example();&lt;/P&gt;&lt;P&gt;Let me know if it works&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Nov 2014 14:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37968#M7602</guid>
      <dc:creator>loredana_cornea</dc:creator>
      <dc:date>2014-11-07T14:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37969#M7603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or alternatively, put this inside your macro:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data test(drop=s);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;length lob $3 state $2;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do s = 'IMR IL', 'IMD IL', 'MMD MO', 'MMR MO', 'HMR IN', 'OMD OH', 'OAD OH';&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lob = scan(s,1); state = scan(s,2);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Nov 2014 15:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37969#M7603</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-11-07T15:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: DATALINES statement inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37970#M7604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is another option that works within a macro:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;213 %macro monthly;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;214 proc sql;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;215&amp;nbsp;&amp;nbsp; create table Lobs (Lob char(3), State char(2));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;216&amp;nbsp;&amp;nbsp; insert into Lobs&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;217&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values ('IMR','IL')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;218&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values ('IMD','IL')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;219&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values ('MMD','MO')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;220&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values ('MMR','MO')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;221&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values ('HMR','IN')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;222&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values ('OMD','OH')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;223&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values ('OAD','OH');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;224 quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;225 %mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;226 %monthly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOTE: Table WORK.LOBS created, with 0 rows and 2 columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOTE: 7 rows were inserted into WORK.LOBS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Nov 2014 20:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATALINES-statement-inside-a-macro/m-p/37970#M7604</guid>
      <dc:creator>mark_alexander_ct_gov</dc:creator>
      <dc:date>2014-11-07T20:13:06Z</dc:date>
    </item>
  </channel>
</rss>

