<?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 why a data step inserted in macro is giving errors in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521922#M141644</link>
    <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two questions in my pgm below.&amp;nbsp; First, the data step 'one' is giving me errors when i insert in the macro.&amp;nbsp; Second, in the data step three,&amp;nbsp; depends on how many "&lt;FONT color="#800000"&gt;treat&lt;/FONT&gt;" variable values i need&amp;nbsp; calculate character variables for the "value" variables. Please suggest. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a1&amp;nbsp; &amp;nbsp; &amp;nbsp;b1&amp;nbsp; &amp;nbsp; &amp;nbsp; c1&lt;/P&gt;
&lt;P&gt;100&amp;nbsp; &amp;nbsp;200&amp;nbsp; &amp;nbsp; 300&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro want;&lt;BR /&gt;data one;
input treat $ value;
cards;
a1 100
b1 200
c1 300
;
run;
proc sql noprint;
    select strip(put(count (distinct treat), best.)) into: cnt from one
  order by treat;
quit;
 %put &amp;amp;cnt.;

proc transpose data=one out=two prefix=T;
var value;
run;
%do i=1 %to &amp;amp;cnt.;
data three;
set two;
n&amp;amp;i.=compress(put(T&amp;amp;i.,5.));&lt;BR /&gt;a1=n1;&lt;BR /&gt;b1=n2;&lt;BR /&gt;c1=n3;&lt;BR /&gt;run;
%end;
run;


%mend;
%want;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Dec 2018 14:38:29 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2018-12-17T14:38:29Z</dc:date>
    <item>
      <title>why a data step inserted in macro is giving errors</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521922#M141644</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two questions in my pgm below.&amp;nbsp; First, the data step 'one' is giving me errors when i insert in the macro.&amp;nbsp; Second, in the data step three,&amp;nbsp; depends on how many "&lt;FONT color="#800000"&gt;treat&lt;/FONT&gt;" variable values i need&amp;nbsp; calculate character variables for the "value" variables. Please suggest. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a1&amp;nbsp; &amp;nbsp; &amp;nbsp;b1&amp;nbsp; &amp;nbsp; &amp;nbsp; c1&lt;/P&gt;
&lt;P&gt;100&amp;nbsp; &amp;nbsp;200&amp;nbsp; &amp;nbsp; 300&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro want;&lt;BR /&gt;data one;
input treat $ value;
cards;
a1 100
b1 200
c1 300
;
run;
proc sql noprint;
    select strip(put(count (distinct treat), best.)) into: cnt from one
  order by treat;
quit;
 %put &amp;amp;cnt.;

proc transpose data=one out=two prefix=T;
var value;
run;
%do i=1 %to &amp;amp;cnt.;
data three;
set two;
n&amp;amp;i.=compress(put(T&amp;amp;i.,5.));&lt;BR /&gt;a1=n1;&lt;BR /&gt;b1=n2;&lt;BR /&gt;c1=n3;&lt;BR /&gt;run;
%end;
run;


%mend;
%want;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2018 14:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521922#M141644</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2018-12-17T14:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: why a data step inserted in macro is giving errors</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521924#M141646</link>
      <description>What errors are you getting?</description>
      <pubDate>Mon, 17 Dec 2018 14:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521924#M141646</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-12-17T14:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: why a data step inserted in macro is giving errors</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521928#M141647</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;SAS doesn't allow to create a dataset with cards or datalines in a macro.&lt;BR /&gt;&lt;BR /&gt;See "Details" section in&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#macro-stmt.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#macro-stmt.htm&lt;/A&gt;</description>
      <pubDate>Mon, 17 Dec 2018 14:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521928#M141647</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-12-17T14:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: why a data step inserted in macro is giving errors</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521932#M141648</link>
      <description>&lt;P&gt;cards or datalines are not allowed in a macro. The ERROR message you get when trying to execute your macro is very clear:&lt;/P&gt;
&lt;PRE&gt;ERROR: The macro WANT 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.ONE has 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

ERROR: The macro WANT will stop executing.
&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Dec 2018 14:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521932#M141648</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-17T14:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: why a data step inserted in macro is giving errors</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521935#M141650</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two questions in my pgm below.&amp;nbsp; First, the data step 'one' is giving me errors when i insert in the macro.&amp;nbsp; Second, in the data step three,&amp;nbsp; depends on how many "&lt;FONT color="#800000"&gt;treat&lt;/FONT&gt;" variable values i need&amp;nbsp; calculate character variables for the "value" variables. Please suggest. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a1&amp;nbsp; &amp;nbsp; &amp;nbsp;b1&amp;nbsp; &amp;nbsp; &amp;nbsp; c1&lt;/P&gt;
&lt;P&gt;100&amp;nbsp; &amp;nbsp;200&amp;nbsp; &amp;nbsp; 300&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;The output of proc transpose looks very much like the required output, only thing to do is dropping the variable _name_. Why do you think that you need macro code at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: Wait, i see you need the values of "treat" as names for the transposed columns. Try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   proc transpose data=one out=two(drop=_name_);
      var value;
      id treat;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2018 15:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-a-data-step-inserted-in-macro-is-giving-errors/m-p/521935#M141650</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-12-17T15:02:29Z</dc:date>
    </item>
  </channel>
</rss>

