<?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: Dynamicaly using column names for into statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488855#M127480</link>
    <description>&lt;P&gt;Thank you for your reply. This helps a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I do not want to hardcode column names. In the next run I may have additional columns like I_PAYMENT_DATE, I_RESPONSE_DATE, etc. I can already hardcode each column using SQL into statement.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Aug 2018 13:04:43 GMT</pubDate>
    <dc:creator>hakki_ergun</dc:creator>
    <dc:date>2018-08-22T13:04:43Z</dc:date>
    <item>
      <title>Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488805#M127447</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using following INTO statement for defining variable. My source table has only one row. I wish to write a dynamic loop statement. If I add further columns to the table, for each column, I wish to run the same SQL statement. So that I can store my macro variables in a table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 405px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22681i79F11A638F206EEA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;PROC SQL NOPRINT; &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;select I_REPORT_DATE &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;into: I_REPORT_DATE &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;from WORK.I_DATES QUIT;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 09:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488805#M127447</guid>
      <dc:creator>hakki_ergun</dc:creator>
      <dc:date>2018-08-22T09:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488809#M127448</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;So that I can store my macro variables in a table" - sorry, doesn't make sense.&amp;nbsp; A table - or dataset - is a physical storage file, which contains data.&amp;nbsp; A macro variable is a memory stored item used in the generation of&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;text&lt;/STRONG&gt;&lt;/U&gt;.&amp;nbsp; It is not stored?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As for your question, why not just just merge that one record on when you need to use the date?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Anyways - as you have not posted test data in the form of a dataset, I am going to assume those are numeric date variables, and you want formatted date output:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data have;&lt;BR /&gt; l_date="01jan2018"d;&lt;BR /&gt; b_date="16Jul2017"d;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt; set have;&lt;BR /&gt; array t{*} _numeric_;&lt;BR /&gt; do i=1 to dim(t);&lt;BR /&gt;   call symputx(cats("mvar",put(i,best.)),put(t{i},date9.));&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;mvar1.;&lt;BR /&gt;%put &amp;amp;mvar2.;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 09:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488809#M127448</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-22T09:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488810#M127449</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/227655"&gt;@hakki_ergun&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using following INTO statement for defining variable. My source table has only one row. I wish to write a dynamic loop statement. If I add further columns to the table, for each column, I wish to run the same SQL statement. So that I can store my macro variables in a table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 405px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22681i79F11A638F206EEA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;PROC SQL NOPRINT; &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;select I_REPORT_DATE &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;into: I_REPORT_DATE &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;from WORK.I_DATES QUIT;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sounds weird. You have data in a dataset and want to move it to macro-variables to add the data to a dataset? Why not adding the data directly? Best thing one can do is not to store data in macro-variables.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 09:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488810#M127449</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-08-22T09:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488812#M127451</link>
      <description>&lt;P&gt;Let me give some further information. I wish to store my filters in a table with column names. Then I'm using into statement for using the values in later filtering. Here is how I use it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Here I use into statement for taking filters*/&lt;/P&gt;&lt;P&gt;PROC SQL NOPRINT; select I_REPORT_DATE into: I_REPORT_DATE from WORK.I_DATES QUIT;&lt;BR /&gt;PROC SQL NOPRINT; select I_END_DATE into: I_END_DATE from WORK.I_DATES QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Here I use filters within a SQL statement*/&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.SAMPLE_OUTPUT AS&lt;BR /&gt;SELECT&lt;/P&gt;&lt;P&gt;t1.reporting_date,&lt;BR /&gt;t1.approach&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FROM prt.PORTFOLIO_TABLE t1&lt;BR /&gt;WHERE t1.reporting_date = "&amp;amp;I_REPORT_DATE"d&lt;BR /&gt;AND t1.ending_date = "&amp;amp;I_END_DATE"d;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this I'm using two PROC SQL statements with INTO function for defining filters. I wish to have a dynamic code. If I input more filters with column names, it would define each of them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 10:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488812#M127451</guid>
      <dc:creator>hakki_ergun</dc:creator>
      <dc:date>2018-08-22T10:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488815#M127454</link>
      <description>&lt;P&gt;Yes, need more understanding of joining.&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table work.sample_output as
  select t1.reporting_date,
         t1.approach
  from   prt.portfolio_table t1
  where  t1.reporting_date=(select i_report_date from work.i_dates)
     and t1.ending_date=(select i_end_date from work.i_dates);
quit;&lt;/PRE&gt;
&lt;P&gt;Or you could join the two:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table work.sample_output as
  select t1.reporting_date,
         t1.approach
  from   prt.portfolio_table t1&lt;BR /&gt;  left join work.i_dates t2&lt;BR /&gt;  on 1=1
  where  t1.reporting_date=t2.i_report_date
     and t1.ending_date=t2.i_end_date;
quit;&lt;/PRE&gt;
&lt;P&gt;In fact there are numerous ways of doing it without converting data into text macro's then converting them back again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 10:18:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488815#M127454</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-22T10:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488824#M127462</link>
      <description>&lt;P&gt;Thank you very much for your response. Unfortunately I just created a simple sample but in fact I will use those macro variables in various steps of a very long process. I do not want to&amp;nbsp;join or write another select for each. I would really prefer to convert them to macro variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 11:26:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488824#M127462</guid>
      <dc:creator>hakki_ergun</dc:creator>
      <dc:date>2018-08-22T11:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488841#M127471</link>
      <description>&lt;P&gt;A WHERE clause doesn't require that you use a date literal.&amp;nbsp; Both of these WHERE statements do the same thing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where datevar = 0;&lt;/P&gt;
&lt;P&gt;where datevar = '01jan1960'd;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can apply that in this situation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set work.i_dates;&lt;/P&gt;
&lt;P&gt;call symputx('i_report_date', i_report_date);&lt;/P&gt;
&lt;P&gt;call symputx('i_end_date', i_end_date);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given that your variables are numerics that are formated (I'm assuming that because they are right-hand justified in your sample output), this will work better than SQL.&amp;nbsp; SQL would add leading blanks when performing a numeric to character conversion, but CALL SYMPUTX will remove any leading blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Later, your WHERE statements can refer to the actual value instead of the date literal:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;FROM prt.PORTFOLIO_TABLE t1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WHERE t1.reporting_date = &amp;amp;I_REPORT_DATE&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AND t1.ending_date = &amp;amp;I_END_DATE;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 12:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488841#M127471</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-22T12:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488843#M127472</link>
      <description>&lt;P&gt;The answer then is why.&amp;nbsp; I have seen it a lot where A simple change to the process, maybe extracting all the required information up front, then processing it, can be a lot quicker, and more efficient.&amp;nbsp; Converting dates to text really just makes it harder to work with them.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 12:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488843#M127472</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-22T12:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488855#M127480</link>
      <description>&lt;P&gt;Thank you for your reply. This helps a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I do not want to hardcode column names. In the next run I may have additional columns like I_PAYMENT_DATE, I_RESPONSE_DATE, etc. I can already hardcode each column using SQL into statement.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 13:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488855#M127480</guid>
      <dc:creator>hakki_ergun</dc:creator>
      <dc:date>2018-08-22T13:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488859#M127483</link>
      <description>&lt;P&gt;Try my initial post, it will do any number of numeric variables, creating mvarX for each of them, X being incremental with each one.&amp;nbsp; No idea how you plan to work with such a setup though.&amp;nbsp; How will you know how many there are, how will you code for all these etc.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 13:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488859#M127483</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-22T13:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488860#M127484</link>
      <description>&lt;P&gt;That brings you into the realm of writing a macro.&amp;nbsp; Is that something you have experience with?&amp;nbsp; Something along the lines of (as the first line):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro nextrun (begin_datevar=, end_datevar=);&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 13:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488860#M127484</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-22T13:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488862#M127485</link>
      <description>&lt;P&gt;I would rather have column names instead of mvarX. I tried as below but it didn't work.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set I_DATES;&lt;BR /&gt;array t{*} _numeric_;&lt;BR /&gt;do i=2 to dim(t);&lt;BR /&gt;call symputx(vname(i), put(t{i},date9.));&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 13:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488862#M127485</guid>
      <dc:creator>hakki_ergun</dc:creator>
      <dc:date>2018-08-22T13:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488865#M127488</link>
      <description>&lt;P&gt;You need to reference the array t{i} with vname:&lt;/P&gt;
&lt;PRE&gt;data have;
 l_date="01jan2018"d;
 b_date="16Jul2017"d;
run;

data _null_;
 set have;
 array t{*} _numeric_;
 do i=1 to dim(t);
   call symputx(vname(t{i}),put(t{i},date9.));
 end;
run;

%put &amp;amp;l_date.;
%put &amp;amp;b_date.;&lt;/PRE&gt;
&lt;P&gt;Do note, that you are making your code as hard to write, and maintain as you possibly can.&amp;nbsp; It will likely never run more than once without needing programmer support.&amp;nbsp; I highly recommend you revisit your code plan and see if there is a better way.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 13:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488865#M127488</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-22T13:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamicaly using column names for into statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488869#M127492</link>
      <description>This solves perfectly. Thank you very much for your responses.</description>
      <pubDate>Wed, 22 Aug 2018 13:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamicaly-using-column-names-for-into-statement/m-p/488869#M127492</guid>
      <dc:creator>hakki_ergun</dc:creator>
      <dc:date>2018-08-22T13:33:01Z</dc:date>
    </item>
  </channel>
</rss>

