<?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: Format in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Format/m-p/51252#M14038</link>
    <description>Hi:&lt;BR /&gt;
  SAS &lt;U&gt;Macro&lt;/U&gt; variables are -ALWAYS- character strings. SAS &lt;U&gt;dataset &lt;/U&gt;variables are either character or numeric. Because a SAS macro variable is a character string, you can use it as needed in a SAS program. For example:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let amt = 500;&lt;BR /&gt;
title "Report on Sales GT &amp;amp;amt";&lt;BR /&gt;
where sales gt &amp;amp;amt;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
              &lt;BR /&gt;
In the above example, the macro variable, &amp;amp;AMT is a character string. In the TITLE statement, the character string resolves to a title statement of:&lt;BR /&gt;
[pre] Report on Sales GT 500[/pre]                         &lt;BR /&gt;
                   &lt;BR /&gt;
The TITLE statement and the string "500" are informative and descriptive. However in the WHERE statement, the 500 goes to the compiler as a numeric constant (as if you had TYPED 500 instead of &amp;amp;AMT).&lt;BR /&gt;
 &lt;BR /&gt;
So when you say the format of a macro variable is either character or numeric, you might mean that you need to use your macro variable as part of a character string or as a numeric constant. However, you go on to explain that the macro variable seems to hold the name of a SAS dataset variable????&lt;BR /&gt;
 &lt;BR /&gt;
I find this somewhat confusing and seeing the code you're using might be helpful here. Knowing a bit more about your data and your goal (what you're trying to accomplish) would also be useful.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Tue, 02 Feb 2010 21:40:58 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2010-02-02T21:40:58Z</dc:date>
    <item>
      <title>Format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format/m-p/51251#M14037</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I've a macro variable for which the format may be either character or numeric.  I want it to be(convert it if necessary) in numeric.  How to check whether the variable is character or numeric?  I used anyalpha and anydigit functions.  The problem is it checks on the name of the variable resolved by the macro variable and not on the value of the variable.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.&lt;BR /&gt;
&lt;BR /&gt;
Sandy.</description>
      <pubDate>Tue, 02 Feb 2010 21:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format/m-p/51251#M14037</guid>
      <dc:creator>Sandhya</dc:creator>
      <dc:date>2010-02-02T21:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: Format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format/m-p/51252#M14038</link>
      <description>Hi:&lt;BR /&gt;
  SAS &lt;U&gt;Macro&lt;/U&gt; variables are -ALWAYS- character strings. SAS &lt;U&gt;dataset &lt;/U&gt;variables are either character or numeric. Because a SAS macro variable is a character string, you can use it as needed in a SAS program. For example:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let amt = 500;&lt;BR /&gt;
title "Report on Sales GT &amp;amp;amt";&lt;BR /&gt;
where sales gt &amp;amp;amt;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
              &lt;BR /&gt;
In the above example, the macro variable, &amp;amp;AMT is a character string. In the TITLE statement, the character string resolves to a title statement of:&lt;BR /&gt;
[pre] Report on Sales GT 500[/pre]                         &lt;BR /&gt;
                   &lt;BR /&gt;
The TITLE statement and the string "500" are informative and descriptive. However in the WHERE statement, the 500 goes to the compiler as a numeric constant (as if you had TYPED 500 instead of &amp;amp;AMT).&lt;BR /&gt;
 &lt;BR /&gt;
So when you say the format of a macro variable is either character or numeric, you might mean that you need to use your macro variable as part of a character string or as a numeric constant. However, you go on to explain that the macro variable seems to hold the name of a SAS dataset variable????&lt;BR /&gt;
 &lt;BR /&gt;
I find this somewhat confusing and seeing the code you're using might be helpful here. Knowing a bit more about your data and your goal (what you're trying to accomplish) would also be useful.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 02 Feb 2010 21:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format/m-p/51252#M14038</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-02-02T21:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format/m-p/51253#M14039</link>
      <description>I had an additional thought about this. You may not need macro variables in order to check the type of a DATASET variable. For example, the VTYPE and VTYPEX functions will return the type of a variable -- they each work slightly differently. They are documented here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000245993.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000245993.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000245994.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000245994.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
The program below creates some fake data -- with 2 character variables C_AGE and C_HEIGHT. Then the type of those 2 variables is checked and new variables are created based on the result of using VTYPE.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
                             &lt;BR /&gt;
** all variables in WORK.NEWCLASS are character except for WEIGHT var;&lt;BR /&gt;
** need some fake data to work with;&lt;BR /&gt;
data newclass(keep=name c_age c_height weight);&lt;BR /&gt;
  length c_age c_height $8;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  c_age = put(age,2.0);&lt;BR /&gt;
  c_height = put(height,4.1);&lt;BR /&gt;
run;&lt;BR /&gt;
                                                     &lt;BR /&gt;
** use VTYPE function;                                        &lt;BR /&gt;
data whattype;&lt;BR /&gt;
  set work.newclass;&lt;BR /&gt;
  if vtype(c_age) = 'C' then do;&lt;BR /&gt;
     newage = input(c_age,best8.);&lt;BR /&gt;
  end;&lt;BR /&gt;
  if vtype(c_height) = 'C' then do;&lt;BR /&gt;
     newheight = input(c_height,best8.);&lt;BR /&gt;
  end;&lt;BR /&gt;
  if vtype(weight) = 'N' then do;&lt;BR /&gt;
     putlog "Weight Variable is already numeric";&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
                                            &lt;BR /&gt;
** show results of conversion;&lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=whattype;&lt;BR /&gt;
  title 'Creating numeric variables, if needed';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 02 Feb 2010 23:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format/m-p/51253#M14039</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-02-02T23:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format/m-p/51254#M14040</link>
      <description>Hi Sandhya.&lt;BR /&gt;
&lt;BR /&gt;
I getting the impression you have some  misunderstood concepts, and some how, I'm getting the feeling you may not need a macro variable for your particular problem.&lt;BR /&gt;
&lt;BR /&gt;
Could you please share your code?&lt;BR /&gt;
&lt;BR /&gt;
Anyway. You cannot apply directly a function over a macro variable name.&lt;BR /&gt;
Either resolve the macro to it's value at run time (ampersand notation) or at compile time using the symget function.&lt;BR /&gt;
[pre]&lt;BR /&gt;
anyalpha("&amp;amp;MYMACRO") or anyalpha(symget('MYMACRO'))&lt;BR /&gt;
[/pre]&lt;BR /&gt;
If your macro holds the name of dataset variable (instead of it's value), then it's the same thing, BUT with one level nesting.&lt;BR /&gt;
[pre]&lt;BR /&gt;
anyalpha("&amp;amp;&amp;amp;&amp;amp;MYMACRO") or anyalpha(symget(symget('MYMACRO')))&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
To check if an alpha to num conversion is possible I kinda prefer using the input function with the ?? options.&lt;BR /&gt;
If the conversion cannot be made, the result should be missing (.)&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000180357.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000180357.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Wed, 03 Feb 2010 08:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format/m-p/51254#M14040</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2010-02-03T08:45:04Z</dc:date>
    </item>
  </channel>
</rss>

