<?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: transforming large number of variables with sas macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473888#M285888</link>
    <description>&lt;P&gt;Might be time to consider if all of the variables are needed or if the data should be in&amp;nbsp;a different structure.&lt;/P&gt;
&lt;P&gt;If you have variables that measure the same thing but are taken at different times so that you have Measure_2010, Measure 2011, Measure_2012... then perhaps it is time to consider have a variable for when measures are taken then having one record per measure&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id variables measure_year Measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you would only have 1 variable, Measure, instead of umpteen Measure variables to transform.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jun 2018 19:29:10 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-06-27T19:29:10Z</dc:date>
    <item>
      <title>transforming large number of variables with sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473878#M285884</link>
      <description>&lt;P&gt;Hi, I am very new to programming in SAS. I have a relatively simple problem that I haven't been able to solve. I&amp;nbsp; want to log transform &amp;gt;1000 variables.&amp;nbsp; I'm trying to use a sas macros to&lt;/P&gt;&lt;P&gt;a)&amp;nbsp; generate a list of all the variables that I want to transform&lt;/P&gt;&lt;P&gt;b) calculate the transformed variable and call them prefix.oldvarname.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the following script to create a list of variable names (vlist) but apparently its just an array of text and not a list of variables.&amp;nbsp; Any suggestions?&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro getvars(dsn);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %global vlist;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name into :vlist separated by ' '&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where memname = upcase("&amp;amp;dsn") and TYPE="num";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;BR /&gt;%mend;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 19:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473878#M285884</guid>
      <dc:creator>cvan-hull</dc:creator>
      <dc:date>2018-06-27T19:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: transforming large number of variables with sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473879#M285885</link>
      <description>&lt;P&gt;You can create a table with the variable names instead of a macro variable, and then use call execute to create dynamic code off that table.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/218081"&gt;@cvan-hull&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, I am very new to programming in SAS. I have a relatively simple problem that I haven't been able to solve. I&amp;nbsp; want to log transform &amp;gt;1000 variables.&amp;nbsp; I'm trying to use a sas macros to&lt;/P&gt;
&lt;P&gt;a)&amp;nbsp; generate a list of all the variables that I want to transform&lt;/P&gt;
&lt;P&gt;b) calculate the transformed variable and call them prefix.oldvarname.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used the following script to create a list of variable names (vlist) but apparently its just an array of text and not a list of variables.&amp;nbsp; Any suggestions?&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%macro getvars(dsn);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %global vlist;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name into :vlist separated by ' '&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where memname = upcase("&amp;amp;dsn") and TYPE="num";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 19:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473879#M285885</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-27T19:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: transforming large number of variables with sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473880#M285886</link>
      <description>&lt;P&gt;PS show us the code you use for transforming one variable. It will be the starting point.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 19:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473880#M285886</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-27T19:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: transforming large number of variables with sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473882#M285887</link>
      <description>&lt;P&gt;With 1,000 variables, your transformation code would likely fit into a single macro variable.&amp;nbsp; (If most variable names are lengthy, there could be a problem since macro variables have an upper limit on length.)&amp;nbsp; Instead of this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select name into : ...............................&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Put all the rest of the formula into your selection:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select catt("myprefix_", name, "= log(", name, ");")&amp;nbsp; into : ............................................&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can utilize the generated code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;&amp;amp;vlist&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 19:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473882#M285887</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-27T19:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: transforming large number of variables with sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473888#M285888</link>
      <description>&lt;P&gt;Might be time to consider if all of the variables are needed or if the data should be in&amp;nbsp;a different structure.&lt;/P&gt;
&lt;P&gt;If you have variables that measure the same thing but are taken at different times so that you have Measure_2010, Measure 2011, Measure_2012... then perhaps it is time to consider have a variable for when measures are taken then having one record per measure&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id variables measure_year Measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you would only have 1 variable, Measure, instead of umpteen Measure variables to transform.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 19:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473888#M285888</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-27T19:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: transforming large number of variables with sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473905#M285889</link>
      <description>&lt;P&gt;This might do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro logvars(dsn);
    proc sql;
        select cats("Log_",name) into :vlist separated by ' '
        from dictionary.columns
        where memname = upcase("&amp;amp;dsn") and TYPE="num";
    quit;
    data log_&amp;amp;dsn;
    set &amp;amp;dsn;
    array v _numeric_;
    array lv &amp;amp;vlist;
    do i = 1 to dim(v);
        if v{i} &amp;gt; 0 then lv{i} = log(v{i});
        end;
    drop i;
    run;
%mend;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jun 2018 20:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transforming-large-number-of-variables-with-sas-macro/m-p/473905#M285889</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-06-27T20:42:48Z</dc:date>
    </item>
  </channel>
</rss>

