<?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: Assign value from another dataset via CALL EXECUTE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-from-another-dataset-via-CALL-EXECUTE/m-p/297722#M312142</link>
    <description>&lt;P&gt;First of all, numbers are not valid SAS names and can therefore not be used to name variables.&lt;/P&gt;
&lt;P&gt;Second, putting data (values) into structure (variable names) is usually a BAD IDEA and better avoided.&lt;/P&gt;
&lt;P&gt;So you're better off putting your values into a separate variable that can then be used in a BY statement to group your further processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be helpful to state the intention behind all this.&lt;/P&gt;</description>
    <pubDate>Mon, 12 Sep 2016 12:00:37 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-09-12T12:00:37Z</dc:date>
    <item>
      <title>Assign value from another dataset via CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-from-another-dataset-via-CALL-EXECUTE/m-p/297718#M312141</link>
      <description>&lt;P&gt;Hi fellow SAS developers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to calculate a new column in a dataset based on values of another dataset.&lt;BR /&gt;&lt;BR /&gt;DS1 contains following columns:&lt;BR /&gt;NUM category&lt;BR /&gt;NUM number_a&lt;BR /&gt;NUM number_b&lt;BR /&gt;&lt;BR /&gt;DS2 contains following columns:&lt;BR /&gt;NUM year&lt;BR /&gt;NUM columns with the name of the category in DS1, meaning the value of the column 'category' in DS1 is the column name in DS2 (numerical column name, e.g. 1.3).&lt;BR /&gt;&lt;BR /&gt;DS1&lt;BR /&gt;-------------------------------&lt;BR /&gt;category | number_a | number_b&lt;BR /&gt;-------------------------------&lt;BR /&gt;1.0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | 5&lt;BR /&gt;1.5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | 3&lt;BR /&gt;-------------------------------&lt;BR /&gt;&lt;BR /&gt;DS2&lt;BR /&gt;---------&lt;BR /&gt;year | 1.0 | 1.5 | 2.5&lt;BR /&gt;----------------------&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; | 0.1 | 0.2 | 0.3&lt;BR /&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; | 0.2 | 0.3 | 0.4&lt;BR /&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; | 0.8 | 0.4 | 0.7&lt;BR /&gt;11&amp;nbsp;&amp;nbsp; | 0.5 | 0.6 | 0.2&lt;BR /&gt;----------------------&lt;BR /&gt;&lt;BR /&gt;First approach was to write the code directly in the CALL EXECUTE statement.&lt;BR /&gt;&lt;BR /&gt;DATA DS1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SET DS1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;number_diff = number_a - number_b;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value_a = CALL EXECUTE("PROC SQL; SELECT 'category'n FROM DS2 WHERE year = " || number_diff || ";&amp;nbsp; QUIT;");&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value_b = CALL EXECUTE("PROC SQL; SELECT 'category'n FROM DS2 WHERE year = " || number_b || "; QUIT;");&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;new_column = (value_b - value_a) / (1 - value_a);&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;A second approach was calling a macro out of the data step with call execute.&lt;BR /&gt;&lt;BR /&gt;%MACRO GET_VALUE(category=, year=);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PROC SQL;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;SELECT '&amp;amp;category.'n&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;/*INTO :pd_value*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;FROM DS2&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;WHERE year = &amp;amp;year.&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;QUIT;&lt;BR /&gt;%MEND GET_VALUE;&lt;BR /&gt;&lt;BR /&gt;DATA DS1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SET DS1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;number_diff = number_a - number_b;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value_a = CALL EXECUTE('%GET_VALUE(category=' || category || ' , year='|| number_diff ||');');&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value_b = CALL EXECUTE('%GET_VALUE(category=' || category || ' , year='|| number_b ||');');&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;I also tried to select into a variable in the macro.&lt;BR /&gt;&lt;BR /&gt;%MACRO GET_VALUE(category=, year=);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PROC SQL;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;SELECT '&amp;amp;category.'n&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTO :return_value&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;FROM DS2&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;WHERE year = &amp;amp;year.&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;QUIT;&lt;BR /&gt;%MEND GET_VALUE;&lt;BR /&gt;&lt;BR /&gt;DATA DS1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SET DS1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;number_diff = number_a - number_b;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return_value = CALL EXECUTE('%GET_VALUE(category=' || category || ' , year=' || number_diff || ');');&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value_a = return_value;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return_value = CALL EXECUTE('%GET_VALUE(category=' ||category || ' , year=' || number_b || ');');&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value_b = return_value;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all hints and solutions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2016 11:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-from-another-dataset-via-CALL-EXECUTE/m-p/297718#M312141</guid>
      <dc:creator>thargassner</dc:creator>
      <dc:date>2016-09-12T11:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value from another dataset via CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-from-another-dataset-via-CALL-EXECUTE/m-p/297722#M312142</link>
      <description>&lt;P&gt;First of all, numbers are not valid SAS names and can therefore not be used to name variables.&lt;/P&gt;
&lt;P&gt;Second, putting data (values) into structure (variable names) is usually a BAD IDEA and better avoided.&lt;/P&gt;
&lt;P&gt;So you're better off putting your values into a separate variable that can then be used in a BY statement to group your further processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be helpful to state the intention behind all this.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2016 12:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-from-another-dataset-via-CALL-EXECUTE/m-p/297722#M312142</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-12T12:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Assign value from another dataset via CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-value-from-another-dataset-via-CALL-EXECUTE/m-p/297904#M312143</link>
      <description>&lt;PRE&gt;
Where is your output ?
Try Hash Table .



&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Sep 2016 03:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-value-from-another-dataset-via-CALL-EXECUTE/m-p/297904#M312143</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-13T03:43:50Z</dc:date>
    </item>
  </channel>
</rss>

