<?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: Use a macrovariable as argument for a put function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macrovariable-as-argument-for-a-put-function/m-p/413429#M101181</link>
    <description>&lt;P&gt;Consider using PUTN instead of PUT.&amp;nbsp; PUTN allows the second parameter (the name of the format) to be an expression rather than a hard-coded name.&amp;nbsp; So if you keep the variable LANG, you should be able to use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sexformatted = putn(sex, cats('sex', lang) ) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That also lets you skip some of the complications of creating macro variables.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Nov 2017 18:05:55 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-11-14T18:05:55Z</dc:date>
    <item>
      <title>Use a macrovariable as argument for a put function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macrovariable-as-argument-for-a-put-function/m-p/413417#M101174</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm struggling with this and I hope someone can give some light on the issue here&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a sample dataset with the column sex (coded in numbers from 1 to 3)&amp;nbsp; and the column lang (language). Also I have 2 formats: sexEn and sexEs that decode the values on the sex column depending on the language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I need is to create a new variable that has the sex decoded on the proper language. See code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;
	value sexEn
	1 = 'Female'
	2 = 'Male'
	3 = 'Indeterminate'
	other = 'Unknown'
	;
	value sexEs
	1 = 'Femenino'
	2 = 'Masculino'
	3 = 'Indeterminado'
	other = 'No informado'
	;
run;

/*for generating the sample dataset*/
%MACRO RandBetween(min/*valor minimo*/, max /*=valor máximo*/);
   (&amp;amp;min. + floor((0+&amp;amp;max.-&amp;amp;min.)*rand("uniform")))
%MEND;

/* steps to generate sample datasete from here */
data test;
	do i=1 to 10;
	lan = %RandBetween(1,3);
	sex = %RandBetween(1,4);
	output;
	end;
run;

data test2;
set test;
if lan = 1 then 
	lang= 'Es';
else lang = 'En';
drop lan;
run;
/*******************to here****************/


/*here I create macrovariables with the language for each row*/
data _null_;
do i = 1 by 1 until (eof);
set test2 end=eof;
call symputx(cats('formsex',i),lang);
end;
run;


/*I need to create a new variable here called sexformatted
by using the needed format
*/
data test3;
do i = 1 by 1 until (eof);
set test2 end=eof;
sexformatted = put(sex,cats('sex',symget(cats('formsex',i)))..);
output;
end;
run;
&lt;/PRE&gt;
&lt;P&gt;but I get an error saying that it is expecting a format name on&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sexformatted = put(sex,cats('sex',symget(cats('formsex',i)))..);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to get around this error? May I be doing something wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for all your feedback&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 17:31:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-macrovariable-as-argument-for-a-put-function/m-p/413417#M101174</guid>
      <dc:creator>iscgonzalez</dc:creator>
      <dc:date>2017-11-14T17:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: Use a macrovariable as argument for a put function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macrovariable-as-argument-for-a-put-function/m-p/413429#M101181</link>
      <description>&lt;P&gt;Consider using PUTN instead of PUT.&amp;nbsp; PUTN allows the second parameter (the name of the format) to be an expression rather than a hard-coded name.&amp;nbsp; So if you keep the variable LANG, you should be able to use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sexformatted = putn(sex, cats('sex', lang) ) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That also lets you skip some of the complications of creating macro variables.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 18:05:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-macrovariable-as-argument-for-a-put-function/m-p/413429#M101181</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-14T18:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: Use a macrovariable as argument for a put function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macrovariable-as-argument-for-a-put-function/m-p/413446#M101188</link>
      <description>Thanks for your help, this worked flawlessly!</description>
      <pubDate>Tue, 14 Nov 2017 18:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-macrovariable-as-argument-for-a-put-function/m-p/413446#M101188</guid>
      <dc:creator>iscgonzalez</dc:creator>
      <dc:date>2017-11-14T18:46:19Z</dc:date>
    </item>
  </channel>
</rss>

