<?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: Using Field Format to Run a Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214529#M39588</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xia,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the information.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After some trial and error I was able to get it to work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if (%datatyp(&amp;amp;NML_NUM_value) ne Char) %then %do;&lt;/P&gt;&lt;P&gt;data tables1;&lt;/P&gt;&lt;P&gt;set tables1;&lt;/P&gt;&lt;P&gt;NML_NUM1 = put(NML_NUM, $5.);&lt;/P&gt;&lt;P&gt;drop NML_NUM;&lt;/P&gt;&lt;P&gt;rename NML_NUM1 = NML_NUM;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I knew there had to be a macro function that checked for the format type. It's odd to me that it's %datatyp and not %datatype. Perhaps that's why i had trouble researching it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Regardless, All, thank you for the assistance!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 04 Aug 2015 16:08:28 GMT</pubDate>
    <dc:creator>Ody</dc:creator>
    <dc:date>2015-08-04T16:08:28Z</dc:date>
    <item>
      <title>Using Field Format to Run a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214522#M39581</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 having some difficulty getting a macro to run based on the format of a field. I'm checking the format and if it's numeric then I want to copy my dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't find a function that returns any of this information in a way I've been able to evaluate in my macro. I've tried playing with vtype, vtypex, vartype, etc... all with no luck. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ideally I'd like something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if %eval (%sysfunc(vartype(&amp;amp;Branch_chk))) = N %then %do;&lt;/P&gt;&lt;P&gt;data employee2;&lt;/P&gt;&lt;P&gt;set employee1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas? I appreciate any thoughts on this. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jul 2015 18:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214522#M39581</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2015-07-30T18:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Format to Run a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214523#M39582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Vartype takes as an argument the name of a dataset variable, which from the location in your code stub does not look like your are evaluating a variable in a set. Is &amp;amp;branch_chk supposed to resolve to the name of a variable or are you looking the value of &amp;amp;branch_chk and trying to determine if that is numeric?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are looking at the type of a variable you will have to use some method that tells SAS which dataset to determine. The following code looks for a variable named Sex in the dataset Sashelp.Class and assigns the type to the macro variable variabletype. The value returned will be char or num. The libname and memname (data set) must either be in all capital letters or modify the code to use UPCASE. You&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let LIB = SASHELP;&lt;/P&gt;&lt;P&gt;%let MEM = CLASS;&lt;/P&gt;&lt;P&gt;%let var = Sex;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select type into : variabletype&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname= "&amp;amp;lib"&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 memname="&amp;amp;mem"&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 name="&amp;amp;var"&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;%put &amp;amp;variabletype;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or some other way to look at the dataset. I can think of at least two others.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jul 2015 19:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214523#M39582</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-30T19:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Format to Run a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214524#M39583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ody&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The VARTYPE function can not be used on its own, one has to know for which data set you want to check. See this example code for how to do it:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/friendly/SAS-macros/blob/master/attrv.sas" title="https://github.com/friendly/SAS-macros/blob/master/attrv.sas"&gt;SAS-macros/attrv.sas at master · friendly/SAS-macros · GitHub&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is an autocall macro that checks the type of the contents of a macro variable, have a look here: &lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#p14qy9r4wu1an0n11kfn30idvy20.htm" title="http://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#p14qy9r4wu1an0n11kfn30idvy20.htm"&gt;SAS(R) 9.4 Macro Language: Reference, Fourth Edition&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bruno&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jul 2015 20:53:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214524#M39583</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2015-07-30T20:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Format to Run a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214525#M39584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ballardw,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the code I provided I am using the max value of the branch field so I can determine if that field is character or numeric. If its numeric I want to change the field to character, or vice versa for other fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My first experiments with the vartype functions would assess each record in my dataset and I wanted to avoid that. I figure taking one example from the field would tell me what I needed to know if only I could somehow assess it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm open to any suggestion. I went down that path because that's all i could think of at the time. I was really hoping for an "if this evaluates to true, then do this" solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bruno,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the links. I'll look into them. The autocall macro looks kinda like what I'm trying to accomplish. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 17:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214525#M39584</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2015-07-31T17:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Format to Run a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214526#M39585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The previous code I posted will do that for one variable, OR you could modify the code to select all of the variables with type='num' or look for type='char'. The code could also select the type for multiple variables by using&lt;/P&gt;&lt;P&gt;&amp;nbsp; name in (&amp;lt;something that returns a list of variable names&amp;gt;)&lt;/P&gt;&lt;P&gt;though I would tend to ensure they are all either upper or lower case and use the appropriated case function on NAME.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How are you planning on making them change type?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 20:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214526#M39585</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-31T20:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Format to Run a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214527#M39586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks ballardw,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was planning on using something along the lines of:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data chk;&lt;/P&gt;&lt;P&gt;set chk;&lt;/P&gt;&lt;P&gt;variable1 = input(variable,$8.);&lt;/P&gt;&lt;P&gt;drop variable;&lt;/P&gt;&lt;P&gt;rename variable1 = variable;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is, once I'm able to identify the variables I want to reformat.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Aug 2015 19:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214527#M39586</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2015-08-03T19:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Format to Run a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214528#M39587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;amp;Branch_chk is a variable name or value ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if it was a value , use %datatype&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%if %datatype(&amp;amp;Branch_chk) = N %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Aug 2015 13:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214528#M39587</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-08-04T13:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Format to Run a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214529#M39588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xia,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the information.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After some trial and error I was able to get it to work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if (%datatyp(&amp;amp;NML_NUM_value) ne Char) %then %do;&lt;/P&gt;&lt;P&gt;data tables1;&lt;/P&gt;&lt;P&gt;set tables1;&lt;/P&gt;&lt;P&gt;NML_NUM1 = put(NML_NUM, $5.);&lt;/P&gt;&lt;P&gt;drop NML_NUM;&lt;/P&gt;&lt;P&gt;rename NML_NUM1 = NML_NUM;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I knew there had to be a macro function that checked for the format type. It's odd to me that it's %datatyp and not %datatype. Perhaps that's why i had trouble researching it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Regardless, All, thank you for the assistance!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Aug 2015 16:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Field-Format-to-Run-a-Macro/m-p/214529#M39588</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2015-08-04T16:08:28Z</dc:date>
    </item>
  </channel>
</rss>

