<?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 Code to change text to variable? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-change-text-to-variable/m-p/272156#M58340</link>
    <description>&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#00ff00"&gt;&lt;STRONG&gt;&lt;FONT color="#993366"&gt;I'm trying to pull in fields called Mort1, Mort2, Mort3, etc. depending on what value is in my variables, MortDuration&amp;amp;i.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;This returns text of Mort1, Mort2, etc. instead of the values:&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%DO&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; k=&amp;amp;i &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%TO&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;j;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;CAT(&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;Mort&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;,Calculated MortDuration&amp;amp;i) as Mortality&amp;amp;i,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%EVAL&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;i+1);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%END&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;&lt;U&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;If I replace the variable I want with a constant, it works:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%SYSFUNC&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(CAT(Mort,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;)) as Mortality&amp;amp;i, (only it always returns Mort1)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;And this returns an error:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color="#0000ff"&gt;%SYSFUNC&lt;/FONT&gt;(CAT(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;Mort&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;,Calculated MortDuration&amp;amp;i)) as Mortality&amp;amp;i,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;U&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;STRONG&gt;Here is my original non-macro, very ugly&amp;nbsp;code that was working&lt;/STRONG&gt;:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/U&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;ifn(Calculated MortDuration1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;FONT face="Courier New"&gt;Mort0&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,ifn(Calculated MortDuration1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,Mort1,ifn(Calculated MortDuration1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,Mort2,ifn(Calculated MortDuration1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,Mort3,ifn(Calculated MortDuration1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,Mort4,.... etc. &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Mortality1,&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 20 May 2016 20:52:57 GMT</pubDate>
    <dc:creator>kiwi</dc:creator>
    <dc:date>2016-05-20T20:52:57Z</dc:date>
    <item>
      <title>Code to change text to variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-change-text-to-variable/m-p/272156#M58340</link>
      <description>&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#00ff00"&gt;&lt;STRONG&gt;&lt;FONT color="#993366"&gt;I'm trying to pull in fields called Mort1, Mort2, Mort3, etc. depending on what value is in my variables, MortDuration&amp;amp;i.&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;This returns text of Mort1, Mort2, etc. instead of the values:&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%DO&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; k=&amp;amp;i &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%TO&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;j;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;CAT(&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;Mort&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;,Calculated MortDuration&amp;amp;i) as Mortality&amp;amp;i,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%EVAL&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;i+1);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%END&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;&lt;U&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;If I replace the variable I want with a constant, it works:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%SYSFUNC&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(CAT(Mort,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;)) as Mortality&amp;amp;i, (only it always returns Mort1)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;And this returns an error:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color="#0000ff"&gt;%SYSFUNC&lt;/FONT&gt;(CAT(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;Mort&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;,Calculated MortDuration&amp;amp;i)) as Mortality&amp;amp;i,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;U&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;STRONG&gt;Here is my original non-macro, very ugly&amp;nbsp;code that was working&lt;/STRONG&gt;:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/U&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;ifn(Calculated MortDuration1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;FONT face="Courier New"&gt;Mort0&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,ifn(Calculated MortDuration1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,Mort1,ifn(Calculated MortDuration1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,Mort2,ifn(Calculated MortDuration1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,Mort3,ifn(Calculated MortDuration1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,Mort4,.... etc. &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Mortality1,&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 20:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Code-to-change-text-to-variable/m-p/272156#M58340</guid>
      <dc:creator>kiwi</dc:creator>
      <dc:date>2016-05-20T20:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Code to change text to variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-change-text-to-variable/m-p/272169#M58343</link>
      <description>&lt;P&gt;Do you need a macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you use VVALUEX function instead?&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 21:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Code-to-change-text-to-variable/m-p/272169#M58343</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-20T21:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Code to change text to variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-change-text-to-variable/m-p/272182#M58344</link>
      <description>&lt;P&gt;Since you don't show any values for Mort1 Mort2 etc I'm guessing that either a FORMAT or INFORMAT may be a better solution.&lt;/P&gt;
&lt;P&gt;Is the result supposed to be a text value or numeric?&lt;/P&gt;
&lt;P&gt;A format like&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; value vmort&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; 0 = 'value'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; 1 = 'other value'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2='something else'&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;put(mortduration&amp;amp;i,vmort.) as mort&amp;amp;i&lt;/P&gt;
&lt;P&gt;or an invalue and input&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And it looks like you Could even use a CASE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;case&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %do k=&amp;amp;i&amp;nbsp;%to&amp;nbsp;&amp;amp;j ; /* what ever value bound&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when mortduration&amp;amp;k = &amp;amp;k then Mort&amp;amp;k&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else &amp;lt;value when none are true&lt;/P&gt;
&lt;P&gt;&amp;nbsp;end as &amp;lt;targetvariablename&amp;gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;your Ifn is incomplete so can't guess more.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you provideed more information about actual values, variable names and what the heck is being done overall to those variables it would help.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 21:22:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Code-to-change-text-to-variable/m-p/272182#M58344</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-20T21:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Code to change text to variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-change-text-to-variable/m-p/272250#M58350</link>
      <description>&lt;P&gt;Sounds like your problem is that you want to select which of the various MORTx real variables to use based on the value of the MORTDURATIONy real variable instead of the value of your MACRO variable. &amp;nbsp;You&amp;nbsp;need to use two %DO loops. One to loop of the set of variables that you are checking the value of (and hence the names of the new variable you are generating) and an inner loop to loop over the set of possible values. &amp;nbsp;Generate a CASE statement since you are already using SQL syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nvar=5 ;
%let nvalues=4 ;
....

%do y=1 %to &amp;amp;nvar ;
,case 
  %do x=1 %to &amp;amp;nvalues ;
  when (calculated MortDuration&amp;amp;y=&amp;amp;x) then Mort&amp;amp;x
  %end;
  end as Mortality&amp;amp;y
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I moved the comma to the beginning of the generated string instead of the end. &amp;nbsp;This is both an easier style for humans to read and it is also easier to generate in this type of %DO loop. &amp;nbsp;It is more likely for this list of variables to be at the end of your&amp;nbsp;SELECT than the beginning since there will normally be id variables preceding them. &amp;nbsp;If they are at the beginning then add another macro variable to contain the comma. &amp;nbsp;Set it to empty before the loop so that the first variable is generated without the leading comma. Then set it to a comma at the end of the loop so that all subsequent variables will have the leading comma.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sep=;
%do i=1 to 5;
  &amp;amp;sep.VAR&amp;amp;i 
  %let sep=,;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 May 2016 16:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Code-to-change-text-to-variable/m-p/272250#M58350</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-05-21T16:22:08Z</dc:date>
    </item>
  </channel>
</rss>

