<?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: Keep field names dynamically in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349398#M81033</link>
    <description>&lt;P&gt;The timing in your logic is incorrect, you're trying to use macro variables before they're created.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To to be clear, you're trying to keep between price_2 and price_9? The min/max are constants on each row or are they dynamic? You should expand&amp;nbsp;your test case.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Apr 2017 12:11:36 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-04-12T12:11:36Z</dc:date>
    <item>
      <title>Keep field names dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349382#M81025</link>
      <description>&lt;P&gt;&amp;nbsp;The dataset below is an example of a dataset I'm using only the real dataset has 100s of fields and about 700 rows with different max/min values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do i drop the field names using the max/min values i.e.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data help(keep = Price_&amp;amp;min--Price_max);&lt;/P&gt;&lt;P&gt;set want;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Min&lt;/TD&gt;&lt;TD&gt;Max&lt;/TD&gt;&lt;TD&gt;Price_1&lt;/TD&gt;&lt;TD&gt;Price_2&lt;/TD&gt;&lt;TD&gt;Price_3&lt;/TD&gt;&lt;TD&gt;Price_4&lt;/TD&gt;&lt;TD&gt;Price_5&lt;/TD&gt;&lt;TD&gt;Price_6&lt;/TD&gt;&lt;TD&gt;Price_7&lt;/TD&gt;&lt;TD&gt;Price_8&lt;/TD&gt;&lt;TD&gt;Price_9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;1.01&lt;/TD&gt;&lt;TD&gt;1.02&lt;/TD&gt;&lt;TD&gt;1.838399&lt;/TD&gt;&lt;TD&gt;2.609743&lt;/TD&gt;&lt;TD&gt;2.932246&lt;/TD&gt;&lt;TD&gt;3.15643&lt;/TD&gt;&lt;TD&gt;3.421783&lt;/TD&gt;&lt;TD&gt;4.083877&lt;/TD&gt;&lt;TD&gt;4.246248&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My full code is below but it's not working.&amp;nbsp;I think a solution to the simple example above would resolve the issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _NULL_;&lt;BR /&gt;if 0 then set test1 nobs=n;&lt;BR /&gt;call symputx('nrows',n);&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data = test1 ; by descending diff; run;&lt;/P&gt;&lt;P&gt;%put &amp;amp;nrows;&lt;BR /&gt;%put &amp;amp;m_diff;&lt;/P&gt;&lt;P&gt;data test2;&lt;BR /&gt;input coin $50.;&lt;BR /&gt;datalines;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%macro temp;&lt;/P&gt;&lt;P&gt;%do j = 1 %to &amp;amp;nrows;&lt;/P&gt;&lt;P&gt;data temp&amp;amp;j(keep = diff coin--maxdate_no Price_USD_&amp;amp;min--Price_USD_&amp;amp;max);&lt;BR /&gt;set test1;&lt;BR /&gt;if _n_ = &amp;amp;j;&lt;BR /&gt;call symputx('min',mindate_no);&lt;BR /&gt;call symputx('max',maxdate_no);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 11:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349382#M81025</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-12T11:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Keep field names dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349398#M81033</link>
      <description>&lt;P&gt;The timing in your logic is incorrect, you're trying to use macro variables before they're created.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To to be clear, you're trying to keep between price_2 and price_9? The min/max are constants on each row or are they dynamic? You should expand&amp;nbsp;your test case.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 12:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349398#M81033</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-12T12:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Keep field names dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349408#M81035</link>
      <description>&lt;P&gt;You misunderstand the concept of rows and columns. &amp;nbsp;Columns are structure - this is what allows you to program with them, they are fixed throughout the data, same type etc. &amp;nbsp;In the case you give, this may be possible as you only have one row, but if you have more than one, what happes if row 1 wants to drop column 1 and row 2 wants to keep it. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you should be doing is, find what value is the min and what is the max, put these in variables and then keep those variables and example:&lt;/P&gt;
&lt;PRE&gt;data want (keep=keep_min keep_max);
  set have;
  array vals{*} price_:;
  keep_min=vals{min};
  keep_max=vals{max};
run;&lt;/PRE&gt;
&lt;P&gt;In fact, you can drop the whole code you have doing there and do it far simpler:&lt;/P&gt;
&lt;PRE&gt;data want (keep=min max);
  set have;
  min=min(of price_:);
  max=max(of price_:);
run;&lt;/PRE&gt;
&lt;P&gt;Do try to avoid overcomplicating things by thinking like Excel.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 12:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349408#M81035</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-12T12:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Keep field names dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349409#M81036</link>
      <description>&lt;P&gt;HI Reeza&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, in the example above I'm trying to keep price_2-price_9. The max and min will be different for each row I want to create a new dataset for each row, keep the rows between the price_min and price_max defined by the min and max field&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 12:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349409#M81036</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-12T12:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: Keep field names dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349415#M81039</link>
      <description>&lt;P&gt;HI RW9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That won't work for my dataset. I want to keep all the fields between the min and max. The min and max will be diffeent for each row so i need to create a different dataset for each row and then deploy the code to keep the fields specified by the min and max fields.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this but it didn't work. If i define the min and max, then I have just two fields that are kept... I need all the fields between the max and min (and this will be different for each row in the original dataset)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro temp;&lt;/P&gt;&lt;P&gt;%do j = 1 %to &amp;amp;nrows;&lt;/P&gt;&lt;P&gt;data temp&amp;amp;j (keep=diff coin--maxdate_no vname(vals{mindate_no})--vname(vals{maxdate_no}));&lt;BR /&gt;set test1;&lt;BR /&gt;if _n_ = &amp;amp;j;&lt;BR /&gt;array vals{*} price_:;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%temp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 12:40:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349415#M81039</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2017-04-12T12:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Keep field names dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349420#M81042</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31948"&gt;@brophymj&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;HI Reeza&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, in the example above I'm trying to keep price_2-price_9. The max and min will be different for each row I want to create a new dataset for each row, keep the rows between the price_min and price_max defined by the min and max field&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Post a bigger example including sample output. It's inclear how the output will be formatted. You can't KEEP different variables on each row. .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 12:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349420#M81042</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-12T12:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Keep field names dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349421#M81043</link>
      <description>&lt;P&gt;Then normalise your data (put the data going down rather than across) as you are looking for data rows which fall between min and max: from&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Min&lt;/TD&gt;
&lt;TD&gt;Max&lt;/TD&gt;
&lt;TD&gt;Price_1&lt;/TD&gt;
&lt;TD&gt;Price_2&lt;/TD&gt;
&lt;TD&gt;Price_3&lt;/TD&gt;
&lt;TD&gt;Price_4&lt;/TD&gt;
&lt;TD&gt;Price_5&lt;/TD&gt;
&lt;TD&gt;Price_6&lt;/TD&gt;
&lt;TD&gt;Price_7&lt;/TD&gt;
&lt;TD&gt;Price_8&lt;/TD&gt;
&lt;TD&gt;Price_9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;9&lt;/TD&gt;
&lt;TD&gt;1.01&lt;/TD&gt;
&lt;TD&gt;1.02&lt;/TD&gt;
&lt;TD&gt;1.838399&lt;/TD&gt;
&lt;TD&gt;2.609743&lt;/TD&gt;
&lt;TD&gt;2.932246&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To:&lt;/P&gt;
&lt;P&gt;Price &amp;nbsp; Value&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.01&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.02&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then its simple select * from have where value between min(value) and max(value). &amp;nbsp;I would question the steps before which have left you with multiple datasets for the same data, and columns defining datarows. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 12:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349421#M81043</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-12T12:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Keep field names dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349446#M81049</link>
      <description>&lt;P&gt;Your easiest method might be to use variable lists. &amp;nbsp;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;(keep = diff coin--maxdate_no Price_USD_: )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The colon means all variable names that begin with "Price_USD_" which probably gives you only the ones that you want.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 13:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-field-names-dynamically/m-p/349446#M81049</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-12T13:38:14Z</dc:date>
    </item>
  </channel>
</rss>

