<?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 Resolving string as a variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Resolving-string-as-a-variable-name/m-p/68705#M14885</link>
    <description>Hi All.&lt;BR /&gt;
&lt;BR /&gt;
I have following dataset where one variable holds the value as other variable names of the same data set.&lt;BR /&gt;
&lt;BR /&gt;
e.g.&lt;BR /&gt;
&lt;BR /&gt;
Dataset: &lt;B&gt;source_ds&lt;/B&gt;;&lt;BR /&gt;
&lt;B&gt;FIELD_ID    FIELD_AVG   FIELD_SUM   REQ_STAT   FIELD_STAT&lt;/B&gt;&lt;BR /&gt;
    01   120   240   FIELD_AVG   .&lt;BR /&gt;
    02   150   300   FIELD_SUM   .&lt;BR /&gt;
    03   140   260   FIELD_SUM   .&lt;BR /&gt;
&lt;BR /&gt;
Here if you see, the Field &lt;B&gt;REQ_STAT  &lt;/B&gt; contains the value of one of the other variables. Now the variable &lt;B&gt;FIELD_STAT&lt;/B&gt; should be assigned to the value of a variable which is specified in the above &lt;B&gt;REQ_STAT&lt;/B&gt; variable.&lt;BR /&gt;
&lt;BR /&gt;
Hence the final output data set should look like as follow:&lt;BR /&gt;
&lt;BR /&gt;
Dataset: &lt;B&gt;TARGET_DS&lt;/B&gt;;&lt;BR /&gt;
&lt;B&gt;FIELD_ID    FIELD_AVG   FIELD_SUM   REQ_STAT   FIELD_STAT&lt;/B&gt;&lt;BR /&gt;
    01   120   240   FIELD_AVG   120&lt;BR /&gt;
    02   150   300   FIELD_SUM   300&lt;BR /&gt;
    03   140   260   FIELD_SUM   260&lt;BR /&gt;
&lt;BR /&gt;
To achieve the same I was trying to use run time macro facility with SYMPUT and SYMGET function.&lt;BR /&gt;
&lt;BR /&gt;
DATA target_ds; &lt;BR /&gt;
   SET source_ds;&lt;BR /&gt;
   CALL SYMPUT('field_val', req_stat);&lt;BR /&gt;
   field_stat = SYMGET('field_val');&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
But when executed above code, the value of macro variable 'field_val' got resolved as a string variable rather than as a variable name.&lt;BR /&gt;
&lt;BR /&gt;
The output was:&lt;BR /&gt;
&lt;BR /&gt;
Dataset: &lt;B&gt;TARGET_DS&lt;/B&gt;;&lt;BR /&gt;
&lt;B&gt;FIELD_ID    FIELD_AVG   FIELD_SUM   REQ_STAT   FIELD_STAT&lt;/B&gt;&lt;BR /&gt;
    01   120   240   FIELD_AVG   FIELD_AVG&lt;BR /&gt;
    02   150   300   FIELD_SUM   FIELD_SUM&lt;BR /&gt;
    03   140   260   FIELD_SUM   FIELD_SUM&lt;BR /&gt;
&lt;BR /&gt;
Here, in the expression, "field_stat = SYMGET('field_val');" the value returned from the symget function should be resolved as variable name rather than a string value.&lt;BR /&gt;
&lt;BR /&gt;
Is it possible to achieve the same?&lt;BR /&gt;
Is there any way to assign the variable name during run time? &lt;BR /&gt;
&lt;BR /&gt;
Any help regarding this would be highly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
regards&lt;BR /&gt;
Kapil Agrawal</description>
    <pubDate>Mon, 12 Jan 2009 13:51:03 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-01-12T13:51:03Z</dc:date>
    <item>
      <title>Resolving string as a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-string-as-a-variable-name/m-p/68705#M14885</link>
      <description>Hi All.&lt;BR /&gt;
&lt;BR /&gt;
I have following dataset where one variable holds the value as other variable names of the same data set.&lt;BR /&gt;
&lt;BR /&gt;
e.g.&lt;BR /&gt;
&lt;BR /&gt;
Dataset: &lt;B&gt;source_ds&lt;/B&gt;;&lt;BR /&gt;
&lt;B&gt;FIELD_ID    FIELD_AVG   FIELD_SUM   REQ_STAT   FIELD_STAT&lt;/B&gt;&lt;BR /&gt;
    01   120   240   FIELD_AVG   .&lt;BR /&gt;
    02   150   300   FIELD_SUM   .&lt;BR /&gt;
    03   140   260   FIELD_SUM   .&lt;BR /&gt;
&lt;BR /&gt;
Here if you see, the Field &lt;B&gt;REQ_STAT  &lt;/B&gt; contains the value of one of the other variables. Now the variable &lt;B&gt;FIELD_STAT&lt;/B&gt; should be assigned to the value of a variable which is specified in the above &lt;B&gt;REQ_STAT&lt;/B&gt; variable.&lt;BR /&gt;
&lt;BR /&gt;
Hence the final output data set should look like as follow:&lt;BR /&gt;
&lt;BR /&gt;
Dataset: &lt;B&gt;TARGET_DS&lt;/B&gt;;&lt;BR /&gt;
&lt;B&gt;FIELD_ID    FIELD_AVG   FIELD_SUM   REQ_STAT   FIELD_STAT&lt;/B&gt;&lt;BR /&gt;
    01   120   240   FIELD_AVG   120&lt;BR /&gt;
    02   150   300   FIELD_SUM   300&lt;BR /&gt;
    03   140   260   FIELD_SUM   260&lt;BR /&gt;
&lt;BR /&gt;
To achieve the same I was trying to use run time macro facility with SYMPUT and SYMGET function.&lt;BR /&gt;
&lt;BR /&gt;
DATA target_ds; &lt;BR /&gt;
   SET source_ds;&lt;BR /&gt;
   CALL SYMPUT('field_val', req_stat);&lt;BR /&gt;
   field_stat = SYMGET('field_val');&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
But when executed above code, the value of macro variable 'field_val' got resolved as a string variable rather than as a variable name.&lt;BR /&gt;
&lt;BR /&gt;
The output was:&lt;BR /&gt;
&lt;BR /&gt;
Dataset: &lt;B&gt;TARGET_DS&lt;/B&gt;;&lt;BR /&gt;
&lt;B&gt;FIELD_ID    FIELD_AVG   FIELD_SUM   REQ_STAT   FIELD_STAT&lt;/B&gt;&lt;BR /&gt;
    01   120   240   FIELD_AVG   FIELD_AVG&lt;BR /&gt;
    02   150   300   FIELD_SUM   FIELD_SUM&lt;BR /&gt;
    03   140   260   FIELD_SUM   FIELD_SUM&lt;BR /&gt;
&lt;BR /&gt;
Here, in the expression, "field_stat = SYMGET('field_val');" the value returned from the symget function should be resolved as variable name rather than a string value.&lt;BR /&gt;
&lt;BR /&gt;
Is it possible to achieve the same?&lt;BR /&gt;
Is there any way to assign the variable name during run time? &lt;BR /&gt;
&lt;BR /&gt;
Any help regarding this would be highly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
regards&lt;BR /&gt;
Kapil Agrawal</description>
      <pubDate>Mon, 12 Jan 2009 13:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-string-as-a-variable-name/m-p/68705#M14885</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-12T13:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving string as a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-string-as-a-variable-name/m-p/68706#M14886</link>
      <description>Macro variables will not change during data step execution, therefore does not your code work.&lt;BR /&gt;
&lt;BR /&gt;
Your example has only two variables to chose between. The easiest is just to hard code an IF-statement. If you in you real life has tons of columns, you may want to build something more generic. If you for instance can have a name standard for you analysis column, maybe you can generate a SELECT/IF/CASE statement as a macro pre-process using table metadata.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Mon, 12 Jan 2009 14:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-string-as-a-variable-name/m-p/68706#M14886</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-01-12T14:03:13Z</dc:date>
    </item>
  </channel>
</rss>

