<?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: Placing macro variable(functions) into second argument of put(source,format) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/415745#M102017</link>
    <description>&lt;P&gt;PUTC and PUTN will take a text argument for the second parameter so you don’t need this macro implementation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At lear&lt;/P&gt;</description>
    <pubDate>Thu, 23 Nov 2017 06:35:08 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-11-23T06:35:08Z</dc:date>
    <item>
      <title>Placing macro variable(functions) into second argument of put(source,format)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/415734#M102009</link>
      <description>&lt;P&gt;I have a few proc format values which I want to use in the second argument of put(source,format). For example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library = work ;
    value GROUP
	0 = 'Controlled Hypertensive Patients'
	1 = 'Uncontrolled Hypertensive Patients';


    value COUNTRY
        0 = 'CHINA'
        1 = 'BRITAIN'
        2 = 'USA';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I&amp;nbsp;plan to use them in a do loop in data step. So lets say I have a dataset called 'have' that contains variables 'GROUP' and 'COUNTRY' (same names as the value formats). This is what I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var_format=GROUP COUNTRY

data want;
set have;
format Variable_label $150.;
do _i=1 to countw(symget('var_format'));
    Variable_label = put( scan(symget('var_format'),_i) , scan(symget('var_format'),_i). ); end; drop _:; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unfortunately, in the second argument of the put(source,format) statement, it gave the following error in the log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Variable_label = put(scan(symget('var_format'),_i),scan(symget('var_format'),_i).);
                                                   ----
                                                    85
                                                    76
ERROR 85-322: Expecting a format name.

ERROR 76-322: Syntax error, statement will be ignored.&lt;/PRE&gt;&lt;P&gt;As such, is there anyway around this problem?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 05:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/415734#M102009</guid>
      <dc:creator>chingweelim</dc:creator>
      <dc:date>2017-11-23T05:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Placing macro variable(functions) into second argument of put(source,format)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/415738#M102013</link>
      <description>&lt;P&gt;PUT function requires a format as second argument. (See error message)&lt;/P&gt;
&lt;P&gt;Format should end with a &lt;STRONG&gt;dot&lt;/STRONG&gt; and optionally length, so you need define:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var_format=GROUP COUNTRY. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use function &lt;STRONG&gt;PUTC&lt;/STRONG&gt; (PUTN for numeric ) with next syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PUTC(source, format.&amp;lt;,w&amp;gt;) &lt;/PRE&gt;
&lt;P&gt;and I would assign a temporary variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; _varx =&amp;nbsp;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;symget&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'var_format'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;);&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;and replace all&amp;nbsp;&lt;STRONG&gt;symget('var_format')&lt;/STRONG&gt; with the _&lt;STRONG&gt;varx&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 05:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/415738#M102013</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-23T05:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Placing macro variable(functions) into second argument of put(source,format)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/415745#M102017</link>
      <description>&lt;P&gt;PUTC and PUTN will take a text argument for the second parameter so you don’t need this macro implementation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At lear&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 06:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/415745#M102017</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-23T06:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Placing macro variable(functions) into second argument of put(source,format)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/415928#M102096</link>
      <description>&lt;P&gt;Hi Reeza and Shmuel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you so much for your help. I did not realize there is a function that allows for text as the second argument. Works like a charm!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 03:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/415928#M102096</guid>
      <dc:creator>chingweelim</dc:creator>
      <dc:date>2017-11-24T03:51:21Z</dc:date>
    </item>
  </channel>
</rss>

