<?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: Separate Character and Numeric Variables in the Macro Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/273992#M54625</link>
    <description>You would probably be better off using DICTIONARY.COLUMNS to get the columns you want based on their TYPE. You can query the tables directly without using PROC CONTENTS first. &lt;BR /&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/070-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/070-30.pdf&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;  There are several examples of how to use the DICTIONARY tables in the Macro Language 1 class.&lt;BR /&gt;&lt;BR /&gt;  Here's an example to get you started:&lt;BR /&gt;proc sql;&lt;BR /&gt;  select name into :cname separated by '~' &lt;BR /&gt;  from dictionary.columns&lt;BR /&gt;  where libname="SASHELP" and memname="CLASS"&lt;BR /&gt;  and type = 'char';&lt;BR /&gt;&lt;BR /&gt;  select name into :nname separated by '~'&lt;BR /&gt;  from dictionary.columns&lt;BR /&gt;  where libname="SASHELP" and memname="CLASS"&lt;BR /&gt;  and type = 'num';&lt;BR /&gt;quit;&lt;BR /&gt;  &lt;BR /&gt;%put character vars are: &amp;amp;cname;&lt;BR /&gt;%put numeric vars are: &amp;amp;nname;&lt;BR /&gt;  &lt;BR /&gt;options mprint symbolgen;&lt;BR /&gt;proc freq data=sashelp.class;&lt;BR /&gt;  table %scan(&amp;amp;cname,1,~) %scan(&amp;amp;cname,2,~);&lt;BR /&gt;run;&lt;BR /&gt;  &lt;BR /&gt;proc means data=sashelp.class;&lt;BR /&gt;  var %scan(&amp;amp;nname,1,~) %scan(&amp;amp;nname,2,~) %scan(&amp;amp;nname,3,~) ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;There are ways to make the program more dynamic. I leave it to you to study other macro techniques to do this.&lt;BR /&gt;&lt;BR /&gt;cynthia&lt;BR /&gt;</description>
    <pubDate>Tue, 31 May 2016 00:19:17 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2016-05-31T00:19:17Z</dc:date>
    <item>
      <title>Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/273985#M54623</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nowadays, I’m trying to create dynamic code process in my SAS project. I have a macro variable which includes 4 columns name(In my real data, it includes many columns, this is my sample code), some of these columns are numeric and some of the other columns are character, in this macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to seperate the character and numeric columns from each other in the macro variable. If I can do this, I want to send character type variables to the PROC FREQ procedure, and send to numeric type variables to the PROC MEANS procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible to create this or similar structure in my foregoing sentences?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My sample code as below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would be so pleased, if I can get useful help from you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data Have;
Length Numeric1 8 Numeric2 8 Character1 $ 32 Character2 $ 32;
Infile Datalines Missover;
Input Numeric1 Numeric2 Character1 Character2;
Datalines;
0.2 0.4 1 0
0.3 0.5 1 2
0.4 0.8 3 1
0.6 0.9 0 2
0.2 0.1 4 3
0.3 0.1 3 2
0.7 0.1 1 4
0.1 0.8 3 3
;
Run;
&amp;nbsp;
%Let Variable=Numeric1 Numeric1 Character1 Character2;

OPTIONS NOLABEL;
ODS OUTPUT Summary=Result;
PROC MEANS DATA=Have MEAN STD MIN MAX N NMISS P1 P5 MEDIAN P95 P99 STACKODSOUTPUT;
VAR Numeric1 Numeric2;
RUN;
&amp;nbsp;
Ods Trace On;
PROC FREQ Data=Have;
Tables Character1 Character2/ NoCum Missing;
Ods Output OneWayFreqs=Want;
Run;
Ods Trace Off;
&amp;nbsp;
Thank you,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Lastly, I tried to seperate the varibles by using PROC CONTENTS OUT= but I'm stopped up, maybe it is not possible, or I need hep&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%Let Variable = Numeric1 Numeric2 Character1 Character2;&lt;BR /&gt;Proc Contents Data=Have Out=Intermediate Noprint; Run;&lt;BR /&gt;Data Want ;&lt;BR /&gt;Set Intermediate /*END=Eof*/;&lt;BR /&gt;Where Type=2 And Name Contains "&amp;amp;Variable." ;&lt;BR /&gt;Run;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2016 22:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/273985#M54623</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-05-30T22:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/273992#M54625</link>
      <description>You would probably be better off using DICTIONARY.COLUMNS to get the columns you want based on their TYPE. You can query the tables directly without using PROC CONTENTS first. &lt;BR /&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/070-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/070-30.pdf&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;  There are several examples of how to use the DICTIONARY tables in the Macro Language 1 class.&lt;BR /&gt;&lt;BR /&gt;  Here's an example to get you started:&lt;BR /&gt;proc sql;&lt;BR /&gt;  select name into :cname separated by '~' &lt;BR /&gt;  from dictionary.columns&lt;BR /&gt;  where libname="SASHELP" and memname="CLASS"&lt;BR /&gt;  and type = 'char';&lt;BR /&gt;&lt;BR /&gt;  select name into :nname separated by '~'&lt;BR /&gt;  from dictionary.columns&lt;BR /&gt;  where libname="SASHELP" and memname="CLASS"&lt;BR /&gt;  and type = 'num';&lt;BR /&gt;quit;&lt;BR /&gt;  &lt;BR /&gt;%put character vars are: &amp;amp;cname;&lt;BR /&gt;%put numeric vars are: &amp;amp;nname;&lt;BR /&gt;  &lt;BR /&gt;options mprint symbolgen;&lt;BR /&gt;proc freq data=sashelp.class;&lt;BR /&gt;  table %scan(&amp;amp;cname,1,~) %scan(&amp;amp;cname,2,~);&lt;BR /&gt;run;&lt;BR /&gt;  &lt;BR /&gt;proc means data=sashelp.class;&lt;BR /&gt;  var %scan(&amp;amp;nname,1,~) %scan(&amp;amp;nname,2,~) %scan(&amp;amp;nname,3,~) ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;There are ways to make the program more dynamic. I leave it to you to study other macro techniques to do this.&lt;BR /&gt;&lt;BR /&gt;cynthia&lt;BR /&gt;</description>
      <pubDate>Tue, 31 May 2016 00:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/273992#M54625</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-05-31T00:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/273998#M54628</link>
      <description>&lt;P&gt;If your program "understands" the order in which the variables were created, you can also use these statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var numeric1-numeric-character2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tables numeric1-character-character2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure if that would lead to some easier approaches or not.&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 01:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/273998#M54628</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-31T01:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274009#M54629</link>
      <description>&lt;P&gt;You know you could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS NOLABEL;
ODS OUTPUT Summary=Result;
PROC MEANS DATA=Have MEAN STD MIN MAX N NMISS P1 P5 MEDIAN P95 P99 STACKODSOUTPUT;
VAR _numeric_;
RUN;
 
PROC FREQ Data=Have;
Tables _character_ / NoCum Missing;
Ods Output OneWayFreqs=Want;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 May 2016 02:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274009#M54629</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-05-31T02:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274020#M54633</link>
      <description>&lt;P&gt;A variation on this works very well when you have a macro variable that contains a subset of the available variable names:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;OPTIONS&lt;/SPAN&gt; NOLABEL&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;ODS&lt;/SPAN&gt; OUTPUT &lt;SPAN class="token procnames"&gt;Summary&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;Result&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;PROC&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;MEANS&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;DATA&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;Have (keep=&amp;amp;macrovar) &lt;SPAN class="token function"&gt;MEAN&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;STD&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;MIN&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;MAX&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;N&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;NMISS&lt;/SPAN&gt; P1 P5 &lt;SPAN class="token function"&gt;MEDIAN&lt;/SPAN&gt; P95 P99 STACKODSOUTPUT&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;VAR&lt;/SPAN&gt; _numeric_&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;RUN&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 
&lt;SPAN class="token procnames"&gt;PROC&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;FREQ&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;Data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;Have (keep=&amp;amp;macrovar)&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;Tables&lt;/SPAN&gt; _character_ &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; NoCum &lt;SPAN class="token function"&gt;Missing&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;Ods&lt;/SPAN&gt; Output OneWayFreqs&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;Want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;Run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 May 2016 03:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274020#M54633</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-31T03:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274220#M54690</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to thank all of yor&amp;nbsp;invaluable&amp;nbsp;recommendations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I benefit from both Cynthia's and PGStats&amp;amp;Astounding methods. When I do some tests on my sample code, I realized that there is a&amp;nbsp;possibility to no character variable or numeric variable in macro variable. After that I tried to build IF statements in my code to prevent my foregoing problem but I need little bit help at this moment Can somebody can help me about my following sample, please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I changed the sample&amp;nbsp;considering the probability of no character variable;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Numeric1 8 Numeric2 8 Character1 $ 32 Character2 $ 32;
Infile Datalines Missover;
Input Numeric1 Numeric2 Character1 Character2;
Datalines;
0.2 0.4 1 0
0.3 0.5 1 2
0.4 0.8 3 1
0.6 0.9 0 2
0.2 0.1 4 3
0.3 0.1 3 2
0.7 0.1 1 4
0.1 0.8 3 3
;
Run;
 
%Let MacroVar=Numeric1 Numeric1;

Data Want;
Set Have (Keep=&amp;amp;MacroVar);
Run;

proc sql;
select name into :cname separated by ' ' 
from dictionary.columns
where libname="WORK" and memname="WANT"
and type = 'char';

select name into :nname separated by ' '
from dictionary.columns
where libname="WORK" and memname="WANT"
and type = 'num';
quit;

%put character vars are: &amp;amp;cname;
%put numeric vars are: &amp;amp;nname;

%Macro Control;
Options NoLabel;
%IF &amp;amp;nname NE " " %THEN %DO;
ODS OUTPUT Summary=Want2;
PROC MEANS DATA=Have (keep=&amp;amp;nname) MEAN STD MIN MAX N NMISS P1 P5 MEDIAN P95 P99 STACKODSOUTPUT;
VAR _numeric_;
RUN;
%END ;
%IF &amp;amp;cname NE " " %THEN %DO;
PROC FREQ Data=Have (keep=&amp;amp;cname);
Tables _character_ / NoCum Missing;
Ods Output OneWayFreqs=Want3;
Run;
%END ;

%Mend;

%Control;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 21:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274220#M54690</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-05-31T21:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274228#M54692</link>
      <description>HI, &lt;BR /&gt;&lt;BR /&gt;Have you tested this on a dataset with all numeric or all character variables?&lt;BR /&gt;&lt;BR /&gt;What is the error message you are receiving?&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
      <pubDate>Tue, 31 May 2016 22:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274228#M54692</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-05-31T22:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274229#M54693</link>
      <description>&lt;P&gt;First, let me give you a faster, simpler way to create &amp;amp;CNAME and &amp;amp;NNAME. &amp;nbsp;This is especially useful when you have a macro variable that contains a list of the variables of interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc contents data=have (keep=&amp;amp;macrovar) noprint out=_contents_ (keep=name type);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select distinct name into : nname from _contents_ where type=1;&lt;/P&gt;
&lt;P&gt;select distinct name into : cname from _contents_ where type=2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The KEEP= option within PROC CONTENTS creates the output data set based on the subset of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then consider how to tell if a macro variable is empty or not. &amp;nbsp;There are a few methods, but this is the one I prefer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if %length(&amp;amp;cname) &amp;gt; 0 %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if %length(&amp;amp;nname) &amp;gt; 0 %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can read an entire paper on the subject. &amp;nbsp;I prefer this method because of simplicity and the differences in effectiveness between the methods is very small.&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 22:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274229#M54693</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-31T22:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274233#M54694</link>
      <description>&lt;P&gt;Astounding,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your sample is very useful, thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in your method, I realized that if I also hold the Character variables in the macro variable -&amp;gt; "%Let MacroVar=Numeric1 Numeric2 Character1 Character2;" , it brings just Numeric1 and Character1, shouldn't it bring -&amp;gt;&amp;nbsp;&lt;SPAN&gt;Numeric1 Numeric2 Character1 Character2 variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I atached an image as below;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3412i2512FAAB359075CF/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Astounding.png" title="Astounding.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Your code helped me but if I don't put any character variables into macro variable, the &amp;amp;cname macro variable isn't created, therefore, I got an error like this &amp;nbsp;-&amp;gt;&amp;nbsp;ERROR 23-7: Invalid value for the KEEP option.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Did I made myself clear? Can we handle it?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let MacroVar=Numeric1 Numeric2 /*Character1 Character2*/;
/*Data Want;*/
/*Set Have (Keep=&amp;amp;MacroVar);*/
/*Run;*/
/**/
/*proc sql;*/
/*select name into :cname separated by ' ' */
/*from dictionary.columns*/
/*where libname="WORK" and memname="WANT"*/
/*and type = 'char';*/
/**/
/*select name into :nname separated by ' '*/
/*from dictionary.columns*/
/*where libname="WORK" and memname="WANT"*/
/*and type = 'num';*/
/*quit;*/
/**/
/*%put character vars are: &amp;amp;cname;*/
/*%put numeric vars are: &amp;amp;nname;*/

Proc Contents Data=Have (Keep=&amp;amp;MacroVar) Noprint 
Out=_Contents_ (Keep=Name Type);
Run;
Proc Sql;
Select Distinct name Into : nname From _Contents_ Where type=1;
Select Distinct name Into : cname From _Contents_ Where type=2;
Run;

%put character vars are: &amp;amp;cname;
%put numeric vars are: &amp;amp;nname;

 
%Macro Control;
Options NoLabel;
%If %Length(&amp;amp;nname) &amp;gt; 0 %Then %Do;
ODS OUTPUT Summary=Want2;
PROC MEANS DATA=Have (keep=&amp;amp;nname) MEAN STD MIN MAX N NMISS P1 P5 MEDIAN P95 P99 STACKODSOUTPUT;
VAR _numeric_;
RUN;
%END;
%If %Length(&amp;amp;cname) &amp;gt; 0 %Then %Do;
PROC FREQ Data=Have (keep=&amp;amp;cname);
Tables _character_ / NoCum Missing;
Ods Output OneWayFreqs=Want3;
Run;
%END;
%Mend;

%Control;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 23:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274233#M54694</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-05-31T23:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274234#M54695</link>
      <description>&lt;P&gt;Hello Cynthia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, I tested it with all numeric or all character but I got this error -&amp;gt;&amp;nbsp;&lt;SPAN&gt;ERROR 23-7: Invalid value for the KEEP option&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because, if there is no character variable in the macro variable, then it doesn't create the cname macro variable therefore I got an error in %IF statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I have some doubt whether I performed Astounding's %IF example correct or not in my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to resolve these two steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 23:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274234#M54695</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-05-31T23:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274236#M54696</link>
      <description>&lt;P&gt;Initialize the variables to blank before using the proc&amp;nbsp;sqld code assignment:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let cname=;&lt;/P&gt;
&lt;P&gt;%let nname=;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token procnames"&gt;Proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;Sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token statement"&gt;Select&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;Distinct&lt;/SPAN&gt; name &lt;SPAN class="token keyword"&gt;Into&lt;/SPAN&gt; : nname &lt;SPAN class="token keyword"&gt;From&lt;/SPAN&gt; _Contents_ &lt;SPAN class="token statement"&gt;Where&lt;/SPAN&gt; type&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token statement"&gt;Select&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;Distinct&lt;/SPAN&gt; name &lt;SPAN class="token keyword"&gt;Into&lt;/SPAN&gt; : cname &lt;SPAN class="token keyword"&gt;From&lt;/SPAN&gt; _Contents_ &lt;SPAN class="token statement"&gt;Where&lt;/SPAN&gt; type&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token procnames"&gt;Run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;However you are not showing how the macro Control is being run in relation to the code that creates those macro variables. You may have a macro scope issue about creating variables in a section of code that treats them as local and hence are not available to %control.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2016 23:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274236#M54696</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-31T23:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274240#M54697</link>
      <description>&lt;P&gt;Absolutely right. &amp;nbsp;Sorry I forgot to mention it. &amp;nbsp;When SQL extracts 0 records, any macro variables populated by data values are not created at all (rather than created and set to null). &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 00:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274240#M54697</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-01T00:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274328#M54720</link>
      <description>&lt;P&gt;Thank you very much everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following code meet my desired output, I got very useful responses, I'm not sure which response should I accept, my desired code as below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So glad I have you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Numeric1 8 Numeric2 8 Character1 $ 32 Character2 $ 32;
Infile Datalines Missover;
Input Numeric1 Numeric2 Character1 Character2;
Datalines;
0.2 0.4 1 0
0.3 0.5 1 2
0.4 0.8 3 1
0.6 0.9 0 2
0.2 0.1 4 3
0.3 0.1 3 2
0.7 0.1 1 4
0.1 0.8 3 3
;
Run;
%Let ModelVar=Numeric1 Numeric2;

Data Both;
Set Have (Keep=&amp;amp;ModelVar);
Run;
%let cname=;
%let nname=;

proc sql;
select name into :cname separated by ' ' 
from dictionary.columns
where libname="WORK" and memname="BOTH"
and type = 'char';

select name into :nname separated by ' '
from dictionary.columns
where libname="WORK" and memname="BOTH"
and type = 'num';
quit;

%put character vars are: &amp;amp;cname;
%put numeric vars are: &amp;amp;nname;
 
%Macro Control;
Options NoLabel;
%If %Length(&amp;amp;nname) &amp;gt; 0 %Then %Do;
ODS OUTPUT Summary=Want2;
PROC MEANS DATA=Have (keep=&amp;amp;nname) MEAN STD MIN MAX N NMISS P1 P5 MEDIAN P95 P99 STACKODSOUTPUT;
VAR _numeric_;
RUN;
%END;
%If %Length(&amp;amp;cname) &amp;gt; 0 %Then %Do;
PROC FREQ Data=Have (keep=&amp;amp;cname);
Tables _character_ / NoCum Missing;
Ods Output OneWayFreqs=Want3;
Run;
%END;
%Mend;

%Control;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2016 09:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/274328#M54720</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-01T09:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/277881#M55864</link>
      <description>Hi PGStats,&lt;BR /&gt;Can you please tell me how do I write/paste codes in forum that look like SAS code rather than the plain text. Also I bookmarked some posts, where do I see those list that I bookmarked? Thanks.</description>
      <pubDate>Thu, 16 Jun 2016 12:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/277881#M55864</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-06-16T12:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/277891#M55866</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35631"&gt;@mlogan﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This article on how to add SAS syntax to a SAS community post might help.&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Getting-Started/How-to-add-SAS-syntax-to-your-post/ta-p/224394" target="_blank"&gt;https://communities.sas.com/t5/Getting-Started/How-to-add-SAS-syntax-to-your-post/ta-p/224394&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind Regards,&lt;/P&gt;
&lt;P&gt;Michelle&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 13:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/277891#M55866</guid>
      <dc:creator>MichelleHomes</dc:creator>
      <dc:date>2016-06-16T13:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Separate Character and Numeric Variables in the Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/277892#M55867</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35631"&gt;@mlogan﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To see your bookmarks, select the arrow next to your name in the top right area when logged in and select My Subscriptions. You will see My Bookmarks listed on the page.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind Regards,&lt;/P&gt;
&lt;P&gt;Michelle&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 13:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-Character-and-Numeric-Variables-in-the-Macro-Variable/m-p/277892#M55867</guid>
      <dc:creator>MichelleHomes</dc:creator>
      <dc:date>2016-06-16T13:34:00Z</dc:date>
    </item>
  </channel>
</rss>

