<?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: Create macro variable from all numeric &amp;amp; categorical variables in a dataset in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Create-macro-variable-from-all-numeric-amp-categorical-variables/m-p/429412#M22558</link>
    <description>&lt;P&gt;There was a very nice&amp;nbsp;article on the &lt;A href="https://communities.sas.com/t5/SAS-Nordic-Users-Group/gp-p/nordic-group" target="_self"&gt;SAS Nordic Group&lt;/A&gt; by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/82850"&gt;@OskarE&lt;/a&gt;&amp;nbsp;on this very topic. Check it out&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Nordic-Users-Group/Juletip-15-Automatic-modeling-with-thousands-millions-of-inputs/gpm-p/422986#M152" target="_self"&gt;Automatic modeling with thousands/millions of inputs but only a few lines of code!&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 20 Jan 2018 22:11:55 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-01-20T22:11:55Z</dc:date>
    <item>
      <title>Create macro variable from all numeric &amp; categorical variables in a dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-macro-variable-from-all-numeric-amp-categorical-variables/m-p/429286#M22554</link>
      <description>&lt;P&gt;I am working on a model that performs regression analysis using the PROC GLMSELECT statement. In order to make my program as dynamic as possible I would like to assign all of the numeric variables from my source table to a macro variable that can be referenced in the model statement, thus allowing the name and number of variables in the input table to change without the need to change the regression code. I would also like to create a macro variable for the categorical variables to be referenced in the Class statement. Please help!&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 21:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-macro-variable-from-all-numeric-amp-categorical-variables/m-p/429286#M22554</guid>
      <dc:creator>tgrandchamp</dc:creator>
      <dc:date>2018-01-19T21:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variable from all numeric &amp; categorical variables in a dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-macro-variable-from-all-numeric-amp-categorical-variables/m-p/429289#M22555</link>
      <description>&lt;P&gt;There are a few ways to get all variables.&amp;nbsp; The one I would recommend for your purposes is PROC CONTENTS (followed by PROC SQL), because you might want to exclude the dependent from your list of variables.&amp;nbsp; For example, you could code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc contents data=have (drop=&amp;amp;dependent)&amp;nbsp; noprint out=_contents_ (keep=name type);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gives you a SAS data set with the name and type of all variables in your data set, excluding the dependent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then SQL takes over:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select strip(name) into : numvars separated by&amp;nbsp; ' '&amp;nbsp; from _contents_&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where type=1;&lt;/P&gt;
&lt;P&gt;select strip(name) into : charvars separated by ' ' from _contents_&lt;/P&gt;
&lt;P&gt;where type=2;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 21:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-macro-variable-from-all-numeric-amp-categorical-variables/m-p/429289#M22555</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-19T21:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variable from all numeric &amp; categorical variables in a dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-macro-variable-from-all-numeric-amp-categorical-variables/m-p/429318#M22557</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185697"&gt;@tgrandchamp&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am working on a model that performs regression analysis using the PROC GLMSELECT statement. In order to make my program as dynamic as possible I would like to assign all of the numeric variables from my source table to a macro variable that can be referenced in the model statement, thus allowing the name and number of variables in the input table to change without the need to change the regression code. I would also like to create a macro variable for the categorical variables to be referenced in the Class statement. Please help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Only you will know which variables are categorical unless you can absolutely positively never ever fails a variable is categorical if there are fewer than XX unique values. If that is the case then Proc freq with nlevels option may be helpful such as:&lt;/P&gt;
&lt;PRE&gt;ods select freq.nlevels;
proc freq data=sashelp.class nlevels;
ods output nlevels = work.mylevels;
run;&lt;/PRE&gt;
&lt;P&gt;which will build a data set with variable and number of unique values, missing and levels of missing. The something like this,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc sql noprint;
   select tablevar into : catvars separated by ' '
   from work.mylevels
   where Nlevels le 6;
quit;
%put &amp;amp;catvars;&lt;/PRE&gt;
&lt;P&gt;works assuming the XX I mentioned above is 6.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 23:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-macro-variable-from-all-numeric-amp-categorical-variables/m-p/429318#M22557</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-19T23:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variable from all numeric &amp; categorical variables in a dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Create-macro-variable-from-all-numeric-amp-categorical-variables/m-p/429412#M22558</link>
      <description>&lt;P&gt;There was a very nice&amp;nbsp;article on the &lt;A href="https://communities.sas.com/t5/SAS-Nordic-Users-Group/gp-p/nordic-group" target="_self"&gt;SAS Nordic Group&lt;/A&gt; by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/82850"&gt;@OskarE&lt;/a&gt;&amp;nbsp;on this very topic. Check it out&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Nordic-Users-Group/Juletip-15-Automatic-modeling-with-thousands-millions-of-inputs/gpm-p/422986#M152" target="_self"&gt;Automatic modeling with thousands/millions of inputs but only a few lines of code!&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 22:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Create-macro-variable-from-all-numeric-amp-categorical-variables/m-p/429412#M22558</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-20T22:11:55Z</dc:date>
    </item>
  </channel>
</rss>

