<?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: Chicken or Egg Problem with Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607403#M176574</link>
    <description>&lt;P&gt;Thank you, I like this solution. It gets rid of the &amp;amp;num problem that I'm dealing with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll have to play around with it. There are data validation steps in the program as well. Times have to be in ascending order and greater than zero. And stopover made sure that if the number of looks is 3 then the user has to enter three different time points.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2019 16:08:52 GMT</pubDate>
    <dc:creator>thewan</dc:creator>
    <dc:date>2019-11-26T16:08:52Z</dc:date>
    <item>
      <title>Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607363#M176540</link>
      <description>&lt;P&gt;This is an example code that boils down a problem I'm facing in a larger code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My program is set up so the user will input these values at the bottom:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) %let num&lt;/P&gt;&lt;P&gt;2) Datalines in the time table (if needed)&lt;/P&gt;&lt;P&gt;3) Macro parameters in %example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to reduce user input burden by getting rid of the free-hanging %let num = 3 statement. The problem is that I can't run the macro without the data step, and the data step uses &amp;amp;num.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions on this? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro example(num=, time=, equal= );

%if &amp;amp;equal=0 %then %do;
data new;
   set time; 
	   array utime (&amp;amp;num) time1 - time&amp;amp;num;
	      do i = 1 to &amp;amp;num;
	         utime[i] = utime[i]; /*if unequal spaced looks, time is taken from dataset time*/
	      end;
	   drop i;
   run;
   %end;

%else %do;
data new;
	array utime (&amp;amp;num) time1 - time&amp;amp;num;
	      do i = 1 to &amp;amp;num;
	         utime[i] = &amp;amp;time/&amp;amp;num; /*if equal spaced looks, time divided by num*/
	      end;
	   drop i;
	run;
	%end;

proc print; run;
%mend;





%let num = 3;					/*input number of looks here. if unequally-spaced times, enter times in below data step*/
data time;
	input time1 - time&amp;amp;num; /*need &amp;amp;num here*/
	infile datalines stopover; 
	datalines;
	24 40 60
	;
run;

%example(num =&amp;amp;num, equal=0, time=60);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 15:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607363#M176540</guid>
      <dc:creator>thewan</dc:creator>
      <dc:date>2019-11-26T15:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607368#M176545</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I want to reduce user input burden by getting rid of the free-hanging %let num = 3 statement. The problem is that I can't run the macro without the data step, and the data step uses &amp;amp;num.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Could you explain more why you have to get rid of this statement? It seems like you are creating your own problem.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What about moving the %let num=3; to the first line of the program. Does that help/meet your needs? Then the user only has to hange the first line of the code and then execute it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 15:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607368#M176545</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-26T15:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607372#M176548</link>
      <description>&lt;P&gt;I want to make sure the user does not miss the statement (all user inputs will be at the bottom).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the final program, there are three data sets that the user will need to fill out (if they choose the unequal times option), and more parameters in the %example statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 15:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607372#M176548</guid>
      <dc:creator>thewan</dc:creator>
      <dc:date>2019-11-26T15:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607373#M176549</link>
      <description>&lt;P&gt;Why can't you put &lt;FONT face="courier new,courier"&gt;DATA TIME;&lt;/FONT&gt; in the macro, and so the last two lines of code are&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let num=3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%example(...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;???&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 15:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607373#M176549</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-26T15:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607375#M176551</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure it answers your question but you can use the colon to specify a list of variables&lt;/P&gt;
&lt;P&gt;with the same prefix. You can also use the dim function to obtain the size of an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro example(time=, equal= );

    data new;
        set time; 

        %if &amp;amp;equal. ne 0 %then %do;
            array utime time:;
            do over utime;
                utime=&amp;amp;time/dim(utime); /*if equal spaced looks, time divided by num*/
            end;
        %end;
    run;

    proc print; run;

%mend;


data time;
    input time1 - time3;
    infile datalines stopover; 
    datalines;
    24 40 60
    ;
run;

%example(equal=0, time=60);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 15:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607375#M176551</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-11-26T15:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607389#M176561</link>
      <description>&lt;P&gt;You only show one line of data.&amp;nbsp; Will the user ever enter more than one line of data?&amp;nbsp; If NOT then just change your data step to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data time;
  input time @@;
datalines;
24 40 60
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the different rows are important then change the data step to include a row counter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data time;
  row+1;
  infile datalines truncover ;
  do until (missing(time));
    input time @;
    if not missing(time) then output;
  end;
datalines;
24 40 60
12 14 16
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can always transform the data to multiple variables if you need it, or change the code to handle the data in this tall format instead.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 15:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607389#M176561</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-26T15:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607391#M176563</link>
      <description>&lt;P&gt;Thanks for taking a look at this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure I understand your suggestion. If I put a data step with datalines in the macro, it generates an error.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 15:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607391#M176563</guid>
      <dc:creator>thewan</dc:creator>
      <dc:date>2019-11-26T15:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607398#M176570</link>
      <description>&lt;P&gt;Thanks for the suggestions. I'm going to see if dim will work as a solution for my program.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607398#M176570</guid>
      <dc:creator>thewan</dc:creator>
      <dc:date>2019-11-26T16:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607403#M176574</link>
      <description>&lt;P&gt;Thank you, I like this solution. It gets rid of the &amp;amp;num problem that I'm dealing with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll have to play around with it. There are data validation steps in the program as well. Times have to be in ascending order and greater than zero. And stopover made sure that if the number of looks is 3 then the user has to enter three different time points.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607403#M176574</guid>
      <dc:creator>thewan</dc:creator>
      <dc:date>2019-11-26T16:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607407#M176578</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173317"&gt;@thewan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, I like this solution. It gets rid of the &amp;amp;num problem that I'm dealing with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll have to play around with it. There are data validation steps in the program as well. Times have to be in ascending order and greater than zero. And stopover made sure that if the number of looks is 3 then the user has to enter three different time points.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you instruct them to enter the number of time points first?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data time;
  input num @;
  do i=1 to num ;
     input time @;
     if time &amp;lt; lag(time) then put 'ERROR: time values out of order.';
    output;
  end;
datalines;
3 10 20 30
;;;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607407#M176578</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-26T16:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: Chicken or Egg Problem with Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607411#M176582</link>
      <description>&lt;P&gt;Thank you again. I can work with this.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:21:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Chicken-or-Egg-Problem-with-Macro/m-p/607411#M176582</guid>
      <dc:creator>thewan</dc:creator>
      <dc:date>2019-11-26T16:21:58Z</dc:date>
    </item>
  </channel>
</rss>

