<?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: Macro for converting char variables to numeric with their labels in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132117#M35895</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is your situation, exactly?&amp;nbsp;&amp;nbsp; 4000 variables looks to be a lot there must be some source of it.&amp;nbsp; Rows / cols ? &lt;/P&gt;&lt;P&gt;Where is your data stores SAS or in RDBMS?&lt;/P&gt;&lt;P&gt;Are there limitiations that are precision related (flosting point) is binning an approach? &lt;BR /&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;The approach of working with arrray-s can be popssible modified and improved for your situation.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 Sep 2013 09:32:46 GMT</pubDate>
    <dc:creator>jakarman</dc:creator>
    <dc:date>2013-09-09T09:32:46Z</dc:date>
    <item>
      <title>Macro for converting char variables to numeric with their labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132116#M35894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to convert my character variables which are more than 4000 to numeric and I'd like to also get their labels assigned to new numeric variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found attached PDF document for this purpose, it's working for a few variables but since I have more than 4000 variables, it's giving error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if anyone has better solutions or idea to resolve this problem ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Sep 2013 00:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132116#M35894</guid>
      <dc:creator>Sas_R</dc:creator>
      <dc:date>2013-09-09T00:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for converting char variables to numeric with their labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132117#M35895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is your situation, exactly?&amp;nbsp;&amp;nbsp; 4000 variables looks to be a lot there must be some source of it.&amp;nbsp; Rows / cols ? &lt;/P&gt;&lt;P&gt;Where is your data stores SAS or in RDBMS?&lt;/P&gt;&lt;P&gt;Are there limitiations that are precision related (flosting point) is binning an approach? &lt;BR /&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;The approach of working with arrray-s can be popssible modified and improved for your situation.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Sep 2013 09:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132117#M35895</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2013-09-09T09:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for converting char variables to numeric with their labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132118#M35896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;overcome the issue of macro var length by just using proc sql; with macro facility to create many variables instead&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name, quote(trim(label))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :vname1-:vname9999, :vlabel1-:vlabel9999 /*It is possible you may need to break this down into 2 select statements, I don't remember if into statement supports range over multiple macro variables */&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&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; memname = "HAVE" and&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; type = "char"&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; /* and any other condition to discriminate the "right" character variables */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro magic();&lt;/P&gt;&lt;P&gt;&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; %do i=1 %to &amp;amp;sqlobs;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_&amp;amp;&amp;amp;vname&amp;amp;i.. = input(&amp;amp;&amp;amp;vname&amp;amp;i.. , best32.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to &amp;amp;sqlobs;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_&amp;amp;&amp;amp;vname&amp;amp;i.. = &amp;amp;&amp;amp;vlabel&amp;amp;i..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; /* closing label statements' semi column */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* add another do loop to drop &amp;amp;&amp;amp;vname&amp;amp;i.. once you are satisfied with test results */&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%magic();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vincent&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Sep 2013 12:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132118#M35896</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-09-09T12:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for converting char variables to numeric with their labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132119#M35897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You do not have to use macro logic to generate code. You can use regular SAS code.&lt;/P&gt;&lt;P&gt;Assume you have dataset named CONTENTS with the output from PROC CONTENTS for your variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename code temp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set contents ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; file code ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; temp = cats('_',_n_);&lt;/P&gt;&lt;P&gt;&amp;nbsp; put temp '=input(' name ',' length 5. '.);'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; / 'rename ' temp '=' name ';'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; / 'drop ' name ';'&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if label ne ' ' then put&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'label&amp;nbsp; ' temp '=' label :$quote. ';'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %inc temp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Message was edited: Fixed DROP statement.&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Sep 2013 12:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132119#M35897</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-09-09T12:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for converting char variables to numeric with their labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132120#M35898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't you need to drop NAME not TEMP.&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; a;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; a = &lt;/SPAN&gt;&lt;SPAN style="color: #800080; background-color: #ffffff;"&gt;'123'&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; b = input(a,&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;f3.1&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;rename&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; b=a;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;drop&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; a;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Sep 2013 12:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132120#M35898</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-09-09T12:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for converting char variables to numeric with their labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132121#M35899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The original source is txt file, I loaded that into SAS but now I need to convert the variables to numeric&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Sep 2013 13:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132121#M35899</guid>
      <dc:creator>Sas_R</dc:creator>
      <dc:date>2013-09-09T13:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for converting char variables to numeric with their labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132122#M35900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Sep 2013 13:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-for-converting-char-variables-to-numeric-with-their-labels/m-p/132122#M35900</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-09-09T13:40:13Z</dc:date>
    </item>
  </channel>
</rss>

