<?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 SAS Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Loop/m-p/86367#M256998</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We are using EpiInfo to manage our lab data for one of our studies. Because of the way we had to set up our data entry forms in EpiInfo when I export data out of EpiInfo into excel to read into SAS, all of the variables are character variables, even if it is a numeric value. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I create a loop in SAS that will convert all of the variables that I want to from Character to Numeric so I don't have to do it manually in Excel. Any help would be greatly appreciated! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 30 Nov 2012 07:34:26 GMT</pubDate>
    <dc:creator>rfarmenta</dc:creator>
    <dc:date>2012-11-30T07:34:26Z</dc:date>
    <item>
      <title>SAS Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Loop/m-p/86367#M256998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We are using EpiInfo to manage our lab data for one of our studies. Because of the way we had to set up our data entry forms in EpiInfo when I export data out of EpiInfo into excel to read into SAS, all of the variables are character variables, even if it is a numeric value. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I create a loop in SAS that will convert all of the variables that I want to from Character to Numeric so I don't have to do it manually in Excel. Any help would be greatly appreciated! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Nov 2012 07:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Loop/m-p/86367#M256998</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2012-11-30T07:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Loop/m-p/86368#M256999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data chars;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; length chr1 char2 char3 $8;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; chr1='23' ; char2='45' ; char3='78' ; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; chr1='44' ; char2='66' ; char3='99' ; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; chr1='11' ; char2='22' ; char3='88' ; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp;&amp;nbsp;&amp;nbsp; strip(put(count(*),best.))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; into&amp;nbsp;&amp;nbsp;&amp;nbsp; :g_numCount&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where&amp;nbsp;&amp;nbsp;&amp;nbsp; libname='WORK'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; and&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memname='CHARS'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; and&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type='char'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;g_numCount;&lt;/P&gt;&lt;P&gt;data nums (keep=numvars1-numvars&amp;amp;g_numCount);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set chars;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array charvars (&amp;amp;g_numCount) $ _character_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array numvars (&amp;amp;g_numCount) 8 numvars1 - numvars&amp;amp;g_numCount;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to dim(numvars);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numvars&lt;I&gt;=input(charvars&lt;I&gt;,best8.);&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Nov 2012 13:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Loop/m-p/86368#M256999</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2012-11-30T13:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Loop/m-p/86369#M257000</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If EpiInfo will export to CSV you may have better luck. Or you can try changing the data type in Excel to numeric&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Nov 2012 15:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Loop/m-p/86369#M257000</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-11-30T15:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Loop/m-p/86370#M257001</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Both of these are good answers.&amp;nbsp; Ballardw's though requires manipulation of the Excel worksheet... if you already open the file for maybe a quick visual review then this won't be too burdensome.&amp;nbsp; You could even write a simple VB-Excel macro to change the format of the columns of interest. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If on the other hand you need a solution that requires no manual intervention and you want to convert all character variables to numeric and the number of character variables varies from file to file then Ahmed's approach is the better of the two &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the names and number of character variable doesn't change then here's an approach similar Ahmed's. It uses a LIBNAME statement to import the Excel file and loads the arrays with a hardcoded list of the character variables that need to be converted.&amp;nbsp; Not tested.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname xls excel '&amp;lt;drive&amp;gt;:/&amp;lt;path&amp;gt;/&amp;lt;filename&amp;gt;.xls';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data epinfo_data_with_numeric_vars;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set xls.&amp;lt;sheet_name&amp;gt;$'n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array charvars {*} $ charvar1-charvar8;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array numvars {*} numvar1 - numvar8;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to dim(numvars);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numvars&lt;I&gt;=input(charvars&lt;I&gt;,best.);&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop charvar1-charvar8;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Be sure to let us know which answer you accept.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Nov 2012 16:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Loop/m-p/86370#M257001</guid>
      <dc:creator>bentleyj1</dc:creator>
      <dc:date>2012-11-30T16:26:24Z</dc:date>
    </item>
  </channel>
</rss>

