<?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/416225#M102179</link>
    <description>&lt;P&gt;Thank you Tom for the advice! I did not know you could use putn() or putc() to take in character expressions in the second argument. Worked like a charm.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2017 00:42:34 GMT</pubDate>
    <dc:creator>chingweelim</dc:creator>
    <dc:date>2017-11-27T00:42:34Z</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/415722#M102003</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;How I am planning to use them is to go through a do loop in data step. So lets say I have a dataset called 'original' that contains variables 'GROUP' and 'COUNTRY' (same names as the value formats). This is what I tried:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var_format=GROUP COUNTRY

data want;
set original;
format Variable_label $150.;
do _i=1 to countw(symget('var_format'));
    Variable_label = put( scan(symget('var_format&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;'),_i) , &lt;U&gt;scan(symget('var_format'),_i). &lt;/U&gt;); &lt;BR /&gt;end; &lt;BR /&gt;drop _:; &lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unfortunately, in the second argument, 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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 01:07:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/415722#M102003</guid>
      <dc:creator>chingweelim</dc:creator>
      <dc:date>2017-11-23T01:07:38Z</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/416133#M102166</link>
      <description>can you post some more details, what i understood is that you are trying to apply 2 formats to the same variable.</description>
      <pubDate>Sat, 25 Nov 2017 09:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/416133#M102166</guid>
      <dc:creator>RM6</dc:creator>
      <dc:date>2017-11-25T09:42:12Z</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/416140#M102168</link>
      <description>&lt;P&gt;The PUT() function requires the format be specified at compile time.&lt;/P&gt;
&lt;P&gt;The PUTN() and PUTC() functions will take a character expression that evaluates to the format specification.&lt;/P&gt;
&lt;P&gt;Here is a worked 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;

%let var_names=GROUP COUNTRY;
%let var_format=GROUP COUNTRY;

data want;
  input &amp;amp;var_names ;
  length Var_Name $32 Var_Value 8 Variable_label $150;
  array values &amp;amp;var_names ;
  do _i=1 to countw(symget('var_format'));
    Var_Name = scan(symget('var_names'),_i);
    Var_Value = values(_i);
    Variable_label = putn( var_value , cats(scan(symget('var_format'),_i),'.') );
    output;
  end;
  drop _i &amp;amp;var_names;
cards;
0 0
0 1
1 2
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                    Var_
Obs    Var_Name    Value    Variable_label

 1     GROUP         0      Controlled Hypertensive Patients
 2     COUNTRY       0      CHINA
 3     GROUP         0      Controlled Hypertensive Patients
 4     COUNTRY       1      BRITAIN
 5     GROUP         1      Uncontrolled Hypertensive Patients
 6     COUNTRY       2      USA&lt;/PRE&gt;
&lt;P&gt;P.S. Don't use FORMAT when you mean LENGTH.&amp;nbsp; FORMAT statement is to attache formats to variables so SAS will know how to print them. SAS already knows how to print character variables, so there is no need to attach the $150. format to the variable VARIABLE_LABEL.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 16:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/416140#M102168</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-25T16:19:56Z</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/416225#M102179</link>
      <description>&lt;P&gt;Thank you Tom for the advice! I did not know you could use putn() or putc() to take in character expressions in the second argument. Worked like a charm.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 00:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Placing-macro-variable-functions-into-second-argument-of-put/m-p/416225#M102179</guid>
      <dc:creator>chingweelim</dc:creator>
      <dc:date>2017-11-27T00:42:34Z</dc:date>
    </item>
  </channel>
</rss>

