<?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: Dynamic prompt in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612780#M178870</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is working now, but I don't know why is only taking the first value? Maybe it's something with the countw but Im not sure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro obten_fecha (fechas);
data lista_fechas;
  format fmt_val DATE9.;
%do i=1 %to %sysfunc(countw(&amp;amp;Fechas.));
  fmt_val = "%scan(&amp;amp;Fechas.,&amp;amp;i)"d;
  output;
%end;
  stop;
run;
%mend;

%let Fechas=&amp;amp;Period;
%obten_fecha(&amp;amp;Fechas);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Dates selected:&lt;/P&gt;&lt;P&gt;17DEC2019&lt;/P&gt;&lt;P&gt;29NOV2019&lt;/P&gt;&lt;P&gt;30AUG2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;17DEC2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Dec 2019 19:13:31 GMT</pubDate>
    <dc:creator>rodrichiez</dc:creator>
    <dc:date>2019-12-18T19:13:31Z</dc:date>
    <item>
      <title>Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612746#M178851</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need some help. I'm trying to get the values generated by a dynamically populated prompt with multiple values, I'm using a macro but there is an error that I can't figure out:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;              _______
              22

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, IN, 
              LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Fechas = &amp;amp;Period;

%macro obten_fecha ();
data lista_fechas;
format fmt_val DATE9.;
%do i=1 %to %sysfunc(countw("&amp;amp;Fechas."));
fmt_val = %scan((&amp;amp;Fechas.),&amp;amp;i);
output;
%end;
run;
%mend;
%obten_fecha;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any help?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 17:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612746#M178851</guid>
      <dc:creator>rodrichiez</dc:creator>
      <dc:date>2019-12-18T17:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612747#M178852</link>
      <description>&lt;P&gt;No macro needed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lista_fechas;
format fmt_val DATE9.;
do i = 1 to countw("&amp;amp;Fechas.");
  fmt_val = scan("&amp;amp;Fechas.",i);
  output;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may have to add the delimiter in the countw() and scan() functions if it is not one of the default delimiters of these functions.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 17:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612747#M178852</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-18T17:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612752#M178854</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still facing the same error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: I'm working with dates values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;38         fmt_val = scan((&amp;amp;Fechas.),i);
NOTE: Line generated by the macro variable "FECHAS".
38         29Nov2019
             _______
             22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, IN, 
              LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  &lt;/CODE&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 18 Dec 2019 18:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612752#M178854</guid>
      <dc:creator>rodrichiez</dc:creator>
      <dc:date>2019-12-18T18:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612755#M178856</link>
      <description>&lt;P&gt;You need to make sure your macro is generating valid SAS code.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;fmt_val = scan((&amp;amp;Fechas.),i);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The scan function wants a valid character expression to scan.&amp;nbsp;20NOV2019 is not a variable name or a character literal.&amp;nbsp; But you could convert it to one by adding quotes around it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;fmt_val = scan("&amp;amp;Fechas.",i);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 18:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612755#M178856</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-18T18:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612756#M178857</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150360"&gt;@rodrichiez&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm still facing the same error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: I'm working with dates values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;38         fmt_val = scan((&amp;amp;Fechas.),i);
NOTE: Line generated by the macro variable "FECHAS".
38         29Nov2019
             _______
             22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, IN, 
              LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;RUN&amp;nbsp;&lt;STRONG&gt;MY CODE AS POSTED!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;You need&amp;nbsp;&lt;EM&gt;quotes&lt;/EM&gt; around string literals.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 18:20:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612756#M178857</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-18T18:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612761#M178859</link>
      <description>&lt;P&gt;Why do you add quotes in the macro expression (where they probably are not needed since they will become part of the value passed to the macro function) but not include them in the SAS expression (where they might be needed to force the compiler to realize the value is a character literal and not a number or the name of a variable).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does the macro variable PERIOD contain? Does it contain numbers like 21883, which are valid date values?&amp;nbsp; That seems to be what your code is assuming. Or does it contain strings that look to humans like dates?&amp;nbsp; If the later are the strings in a format that the DATE informat would recognize?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's assume that the macro variable has string that look like 30NOV2019.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro obten_fecha (fechas);
data lista_fechas;
  format fmt_val DATE9.;
%do i=1 %to %sysfunc(countw(&amp;amp;Fechas.));
  fmt_val = "%scan(&amp;amp;Fechas.,&amp;amp;i)"d ;
  output;
%end;
  stop;
run;
%mend;

%let period=30NOV2019 31DEC2019;
%obten_fecha(&amp;amp;period);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Dec 2019 18:29:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612761#M178859</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-18T18:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612780#M178870</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is working now, but I don't know why is only taking the first value? Maybe it's something with the countw but Im not sure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro obten_fecha (fechas);
data lista_fechas;
  format fmt_val DATE9.;
%do i=1 %to %sysfunc(countw(&amp;amp;Fechas.));
  fmt_val = "%scan(&amp;amp;Fechas.,&amp;amp;i)"d;
  output;
%end;
  stop;
run;
%mend;

%let Fechas=&amp;amp;Period;
%obten_fecha(&amp;amp;Fechas);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Dates selected:&lt;/P&gt;&lt;P&gt;17DEC2019&lt;/P&gt;&lt;P&gt;29NOV2019&lt;/P&gt;&lt;P&gt;30AUG2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;17DEC2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 19:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612780#M178870</guid>
      <dc:creator>rodrichiez</dc:creator>
      <dc:date>2019-12-18T19:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612785#M178872</link>
      <description>What does PERIOD actually contain? How did you create it?&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Dec 2019 19:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612785#M178872</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-18T19:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612802#M178882</link>
      <description>&lt;P&gt;Period is a dynamic prompt, where the user select from a list of values from the data source FECHAS_PROMPT. See attached images.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Period prompt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Period.JPG" style="width: 284px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34936i673C6A73D9ACF037/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Period.JPG" alt="Period.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data source:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Source Table.JPG" style="width: 152px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34938i3F0ED89A54A02DF7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Source Table.JPG" alt="Source Table.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 19:46:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612802#M178882</guid>
      <dc:creator>rodrichiez</dc:creator>
      <dc:date>2019-12-18T19:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612808#M178886</link>
      <description>&lt;P&gt;You need to figure out where the selected values actually get stored.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It used to place them into a series of macro variables. Like PERIOD1, PERIOD2, ... .&amp;nbsp; and create another macro variable that had the number.&amp;nbsp; Use %put _user_ to see all of the macro variables.&amp;nbsp; I think the number might be in a macro variable named PERIOD0.&amp;nbsp; But perhaps is is something else.&amp;nbsp; You might also check what it does when user selects only one value instead of multiple values as that was also tricky.&lt;/P&gt;
&lt;P&gt;So you probably need something like this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to &amp;amp;period0 ;
  fmt_val = "&amp;amp;&amp;amp;period&amp;amp;i"d ;
  output;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Dec 2019 19:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612808#M178886</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-18T19:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic prompt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612810#M178888</link>
      <description>&lt;P&gt;Thank&amp;nbsp; you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; ! It is working fine now. Thanks for your help. I figured out that the macro variable Period_count is the number of selected dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro obten_fecha (fechas);
data lista_fechas;
  format fmt_val DATE9.;
%do i=1 %to &amp;amp;Period_count;
  fmt_val = "&amp;amp;&amp;amp;Period&amp;amp;i"d;
  output;
%end;
  stop;
run;
%mend;

%let Fechas=&amp;amp;Period;
%obten_fecha(&amp;amp;Fechas);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Dec 2019 20:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-prompt/m-p/612810#M178888</guid>
      <dc:creator>rodrichiez</dc:creator>
      <dc:date>2019-12-18T20:06:05Z</dc:date>
    </item>
  </channel>
</rss>

