<?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: How do I reference the values from vertical macro list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745793#M233853</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;As I understand something is wrong with&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;referencing the macro list values.&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whenever you have problems like this with a macro, please run the command&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then re-run your macro. This adds additional information into the LOG that can help you debug the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still can't figure out what is wrong, then please show us the LOG for this macro (we need to see 100% of the log of a run of the macro, all of it, with nothing chopped out). When you show us the LOG, please copy the log as text and paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon. This formats the log to make it much more readable, and helps us help you.&amp;nbsp;&lt;STRONG&gt;DO NOT SKIP THIS STEP.&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Jun 2021 13:14:06 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-06-04T13:14:06Z</dc:date>
    <item>
      <title>How do I reference the values from vertical macro list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745784#M233848</link>
      <description>&lt;P&gt;Hi! I'm working on SAS EG.&lt;BR /&gt;I have a task of &lt;STRONG&gt;automatically&lt;/STRONG&gt; running the program several times, producing several data sets.&lt;BR /&gt;Every time the program should run but &lt;STRONG&gt;change the date&lt;/STRONG&gt; on which the data is loaded.&lt;BR /&gt;The program should take &lt;STRONG&gt;each date from vertical macro list&lt;/STRONG&gt; (data set "Dates" in code below).&lt;BR /&gt;So, for example, user set the range of dates and the program should run on every date in that range.&lt;BR /&gt;&lt;BR /&gt;The code first make the list of dates. Then it creates the vertical macro list with macro variable &lt;STRONG&gt;obs_date &lt;/STRONG&gt;and macro variable &lt;STRONG&gt;numdates&lt;/STRONG&gt; which stores number of days. Then it executes main code of the program.&lt;BR /&gt;The code that I have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let BeginDate = 01jan2019;
%let EndDate = 01mar2019;
%let Months = intck('month',"&amp;amp;BeginDate."d,"&amp;amp;EndDate."d);

data dates;
    do m = 0 to &amp;amp;months.;
    first_of_month = intnx('month',"&amp;amp;BeginDate."d,m,'s');
     last_of_month = intnx('month', "&amp;amp;BeginDate."d,m,'e');
output;
end;
format first_of_month last_of_month date9.;
run;

%Macro pos;
data _null_;
set dates end=eof;
call symputx(cats('obs_date',_N_),last_of_month);
if eof then call symputx('numdates',_n_);
run;

%do i=1 %to &amp;amp;numdates.;

%let date_= %sysfunc(putn(%sysfunc(inputn(&lt;STRONG&gt;&amp;amp;&amp;amp;obs_date&amp;amp;i&lt;/STRONG&gt;,anydtdte9.)),datetime20.));
&lt;BR /&gt;proc sql;

CREATE TABLE WORK.OPEN_POS_&lt;STRONG&gt;&amp;amp;&amp;amp;obs_date&amp;amp;i&lt;/STRONG&gt; (COMPRESS=YES) as
SELECT	f1.Name as PARTY_NAME,
	&lt;EM&gt;&lt;STRONG&gt;...code...&lt;/STRONG&gt;&lt;/EM&gt;
from EQ_TRADES t
		&lt;EM&gt;&lt;STRONG&gt;...joins...&lt;/STRONG&gt;&lt;/EM&gt;
where (t.TRADE_DATE&amp;lt;=&amp;amp;date_  and t.DUE_DATE&amp;gt;=&amp;amp;date_ and t.TRADE_DATE&amp;lt;t.DUE_DATE) and t.FIRM_ID in (SELECT * FROM work.inn)
	
quit;

%end;
%mend pos;
%pos&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As a result I have got nothing. Several empty data sets. Which is wrong.&lt;BR /&gt;&lt;BR /&gt;As I understand something is wrong with &lt;STRONG&gt;referencing the macro list values.&lt;/STRONG&gt;&lt;BR /&gt;So I think something is wrong here:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_= %sysfunc(putn(%sysfunc(inputn(&lt;STRONG&gt;&amp;amp;&amp;amp;obs_date&amp;amp;i&lt;/STRONG&gt;,anydtdte9.)),datetime20.));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or here:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where (t.TRADE_DATE&amp;lt;=&lt;STRONG&gt;&amp;amp;date_&lt;/STRONG&gt;  and t.DUE_DATE&amp;gt;=&lt;STRONG&gt;&amp;amp;date_&lt;/STRONG&gt; and t.TRADE_DATE&amp;lt;t.DUE_DATE)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I write this code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_= "%sysfunc(putn(%sysfunc(inputn(&amp;amp;&amp;amp;obs_date&amp;amp;i,anydtdte9.)),date9.)):0:0:0"dt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then SAS says "Invalid date/time/datetime constant "________ .:0:0:0"dt".&lt;BR /&gt;&lt;BR /&gt;The values stored in t.TRADE_DATE and in t.DUE_DATE are in datetime20. format.&lt;BR /&gt;The values in vertical macro list are in SAS format (numeric values from 01.01.1960).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help to solve this problem. Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 13:03:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745784#M233848</guid>
      <dc:creator>Easybeat</dc:creator>
      <dc:date>2021-06-04T13:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reference the values from vertical macro list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745792#M233852</link>
      <description>&lt;P&gt;This first problem I see is the third line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Months = intck('month',"&amp;amp;BeginDate."d,"&amp;amp;EndDate."d);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want MONTHS to be a number you need to wrap the INTCK() function in in the %SYSFUNC() macro function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also remove the quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Months = %sysfunc(intck(month,"&amp;amp;BeginDate."d,"&amp;amp;EndDate."d));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Jun 2021 13:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745792#M233852</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-04T13:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reference the values from vertical macro list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745793#M233853</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;As I understand something is wrong with&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;referencing the macro list values.&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whenever you have problems like this with a macro, please run the command&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then re-run your macro. This adds additional information into the LOG that can help you debug the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still can't figure out what is wrong, then please show us the LOG for this macro (we need to see 100% of the log of a run of the macro, all of it, with nothing chopped out). When you show us the LOG, please copy the log as text and paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon. This formats the log to make it much more readable, and helps us help you.&amp;nbsp;&lt;STRONG&gt;DO NOT SKIP THIS STEP.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 13:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745793#M233853</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-04T13:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reference the values from vertical macro list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745795#M233855</link>
      <description>&lt;P&gt;It looks like you are generating a dataset with DATE values.&amp;nbsp; And your SQL code needs DATETIME values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At some point you need to convert from one to the other.&lt;/P&gt;
&lt;P&gt;Since your data step is putting the raw number of days in to the macro "array" you could convert it at the point of creating the macro variable DATE_ .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_= %sysfunc(dhms(&amp;amp;&amp;amp;obs_date&amp;amp;i,0,0,0));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now DATE_ will have the raw number of seconds datetime value instead of the raw number of days date value that was in OBS_DATE1.&amp;nbsp; &amp;nbsp;So you can use it to compare to your datetime variables in your SQL code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;t.TRADE_DATE&amp;lt;=&amp;amp;date_&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or just generate DATETIME values into the macro variables.&lt;/P&gt;
&lt;P&gt;So here is a cleaned up version of your macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro pos(dsn=dates);
%local i ymd;

data _null_;
  if eof then call symputx('numdates',_n_-1,'L');
  set &amp;amp;dsn end=eof;
  call symputx(cats('obs_date',_N_),dhms(last_of_month,0,0,0),'L');
run;

proc sql;
%do i=1 %to &amp;amp;numdates.;
  %let ymd=%sysfunc(datepart(&amp;amp;&amp;amp;obs_date&amp;amp;i),yymmddn8.);
  CREATE TABLE WORK.OPEN_POS_&amp;amp;ymd (COMPRESS=YES) as
  SELECT f1.Name as PARTY_NAME
   ...code...
  from EQ_TRADES t
    ...joins...
  where (t.TRADE_DATE&amp;lt;=&amp;amp;&amp;amp;obs_date&amp;amp;i and t.DUE_DATE&amp;gt;=&amp;amp;&amp;amp;obs_date&amp;amp;i and t.TRADE_DATE&amp;lt;t.DUE_DATE)
    and t.FIRM_ID in (SELECT * FROM work.inn)
  ;
%end;
quit;
%mend pos;
%pos;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 13:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745795#M233855</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-04T13:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I reference the values from vertical macro list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745805#M233862</link>
      <description>Yep. This %let date_= %sysfunc(dhms(&amp;amp;&amp;amp;obs_date&amp;amp;i,0,0,0)); works perfectly!&lt;BR /&gt;Thank you a lot!&lt;BR /&gt;&lt;BR /&gt;The code works slower than I thought, though &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; Will try later your cleaned up version, maybe it will make it faster:)</description>
      <pubDate>Fri, 04 Jun 2021 13:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-reference-the-values-from-vertical-macro-list/m-p/745805#M233862</guid>
      <dc:creator>Easybeat</dc:creator>
      <dc:date>2021-06-04T13:51:30Z</dc:date>
    </item>
  </channel>
</rss>

