<?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: How to convert text in a character variable into datastep code? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137469#M27776</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;is this a one time change or being implemented as part of larger process.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if its a one time change, i'd proc print the data set and copy and paste it into my SAS code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;otherwise i think you need to go into macro coding using %put to create a program and then %include it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 25 Jan 2015 21:12:38 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-01-25T21:12:38Z</dc:date>
    <item>
      <title>How to convert text in a character variable into datastep code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137468#M27775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am recoding a large number of coded character variables into dummy variables.&amp;nbsp; I am using one of the published routines that creates a series of If-Then statements and then stores then in a character variable in a SAS dataset.&amp;nbsp; Unfortunately, that routine did not indicate how to use the character variable to create executable SAS datastep statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dataset work.dummy code...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SAS_Code_Var&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If orig_var eq 'a'&amp;nbsp; Then orig_var_a =1;&amp;nbsp; Else orig_var_a =0;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If orig_var eq 'b'&amp;nbsp; Then orig_var_b =1;&amp;nbsp; Else orig_var_b =0;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;What is a good way to use this variable to implement executable SAS code?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Jan 2015 21:00:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137468#M27775</guid>
      <dc:creator>rrempala</dc:creator>
      <dc:date>2015-01-25T21:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text in a character variable into datastep code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137469#M27776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;is this a one time change or being implemented as part of larger process.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if its a one time change, i'd proc print the data set and copy and paste it into my SAS code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;otherwise i think you need to go into macro coding using %put to create a program and then %include it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Jan 2015 21:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137469#M27776</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-01-25T21:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text in a character variable into datastep code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137470#M27777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dummy;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set dummy;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute(SAS_Code_Var);&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Jan 2015 21:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137470#M27777</guid>
      <dc:creator>BurntDirt</dc:creator>
      <dc:date>2015-01-25T21:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text in a character variable into datastep code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137471#M27778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want a shorter solution: orig_var_a = (orig_var eq 'a'); will give you the same result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Jan 2015 22:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137471#M27778</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2015-01-25T22:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text in a character variable into datastep code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137472#M27779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The easiest way is to use a a data step to write a program and then %INCLUDE the generated code.&amp;nbsp; You can also use CALL EXECUTE to generate the program, but that is much harder to debug since you do not have a physical file that you examine for mistakes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that you cannot just execute an IF statement, it has to be part of a data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;filename&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; code &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;temp&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;_null_&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; work.dummy ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;file&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; code ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; put SAS_code_var;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; have ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%inc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; code / source2 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Jan 2015 00:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137472#M27779</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-01-26T00:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text in a character variable into datastep code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137473#M27780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Depending on how this code is generated (i.e. a macro) perhaps you could embed that directly in a data step?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Jan 2015 01:08:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137473#M27780</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-01-26T01:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text in a character variable into datastep code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137474#M27781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To be honest, if your code is just a series of if statements over a set of variables why not do:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct NAME&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :LIST&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from SASHELP.VCOLUMN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where LIBNAME="WORK" and MEMNAME="ABC";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select count(distinct NAME)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into&amp;nbsp;&amp;nbsp; :TOT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp; SASHELP.VCOLUMN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where LIBNAME="WORK" and MEMNAME="ABC";&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array to_process{&amp;amp;TO_PROCESS.} $20. (&amp;amp;LIST.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array done{&amp;amp;TO_PROCESS.} 8.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do I=1 to &amp;amp;TO_PROCESS.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select(to_process{I});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when ('a') done{I}=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when ('b') done{I}=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; otherwise;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that this will give you a series of variables DONEx, having the numeric suffix after variable names is easier to deal with when talking about processing multiple columns (i.e. your example would be far easier if your variables were ORIG_VAR_x, then you would just define a range.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Jan 2015 09:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-text-in-a-character-variable-into-datastep-code/m-p/137474#M27781</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-01-26T09:10:44Z</dc:date>
    </item>
  </channel>
</rss>

