<?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: Display the formatted value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Display-the-formatted-value/m-p/299779#M63273</link>
    <description>&lt;P&gt;You cannot &lt;U&gt;assign&lt;/U&gt; a format dynamically. A column has a format, or it doesn't. Putting a format statement into an if block is useless, as the format assignment takes place when the data step is compiled and the PDV is created.&lt;/P&gt;
&lt;P&gt;You can conditionally use the put function to create a new character variable like&lt;/P&gt;
&lt;P&gt;if (invar has specific value)&lt;/P&gt;
&lt;P&gt;then outvar=put(invar,format_a.);&lt;/P&gt;
&lt;P&gt;else outvar=put(invar,format_b.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am still checking what goes wrong inside your macro.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Sep 2016 08:37:48 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-09-21T08:37:48Z</dc:date>
    <item>
      <title>Display the formatted value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Display-the-formatted-value/m-p/299773#M63271</link>
      <description>&lt;P&gt;I am trying to write the code such that whenever the country count is LE to the freq parameter then the required continent format should be applied to the particular country. below is my code please give some suggestions to get the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here below am to trying to assign the format to the variable whose frequency is equal or less to the freq parameter but instead is displaying this error-----&amp;gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Line generated by the macro variable "VARIABLE".&lt;BR /&gt;1 country&lt;BR /&gt; -------&lt;BR /&gt; 73&lt;BR /&gt; 76&lt;/P&gt;
&lt;P&gt;ERROR 73-322: Expecting an =.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA .COUNTRY;&lt;BR /&gt;input country $25.;&lt;BR /&gt;CARDS;&lt;BR /&gt;INDIA &lt;BR /&gt;INDIA&lt;BR /&gt;INDIA&lt;BR /&gt;INDIA&lt;BR /&gt;SPAIN&lt;BR /&gt;SPAIN&lt;BR /&gt;SPAIN&lt;BR /&gt;SPAIN&lt;BR /&gt;GERMANY&lt;BR /&gt;GERMANY&lt;BR /&gt;GERMANY&lt;BR /&gt;GERMANY&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%macro Country_Check (indsn=, variable=, outdsn=,freq=);&lt;/P&gt;
&lt;P&gt;PROC SORT DATA=&amp;amp;indsn;&lt;BR /&gt; by &amp;amp;variable;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;PROC FREQ DATA=&amp;amp;indsn;&lt;BR /&gt; TABLES &amp;amp;variable / noprint out=counts (KEEP=&amp;amp;variable count);&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;proc format;&lt;BR /&gt; value $city 'INDIA'='ASIA'&lt;BR /&gt; 'GERMANY'='EUROPE'&lt;BR /&gt; 'SPAIN'='EUROPE'&lt;BR /&gt; 'BELGIUM'='EUROPE'&lt;BR /&gt; 'FRANCE'='EUROPE'&lt;BR /&gt; other='UNKNOWN';&lt;/P&gt;
&lt;P&gt;data &amp;amp;outdsn;&lt;BR /&gt; MERGE &amp;amp;indsn counts;&lt;BR /&gt; By &amp;amp;variable;&lt;BR /&gt; if count &amp;lt;= &amp;amp;Freq then do&lt;BR /&gt; format &amp;amp;variable $city.;&lt;BR /&gt; end;&lt;BR /&gt; DROP count;&lt;BR /&gt; run;&lt;BR /&gt;proc print data = &amp;amp;outdsn; run;&lt;BR /&gt; %MEND Country_Check;&lt;/P&gt;
&lt;P&gt;%Country_Check (indsn=myfile.COUNTRY, variable=country, outdsn=want1, Freq=4);&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 08:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Display-the-formatted-value/m-p/299773#M63271</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-09-21T08:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Display the formatted value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Display-the-formatted-value/m-p/299779#M63273</link>
      <description>&lt;P&gt;You cannot &lt;U&gt;assign&lt;/U&gt; a format dynamically. A column has a format, or it doesn't. Putting a format statement into an if block is useless, as the format assignment takes place when the data step is compiled and the PDV is created.&lt;/P&gt;
&lt;P&gt;You can conditionally use the put function to create a new character variable like&lt;/P&gt;
&lt;P&gt;if (invar has specific value)&lt;/P&gt;
&lt;P&gt;then outvar=put(invar,format_a.);&lt;/P&gt;
&lt;P&gt;else outvar=put(invar,format_b.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am still checking what goes wrong inside your macro.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 08:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Display-the-formatted-value/m-p/299779#M63273</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-21T08:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Display the formatted value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Display-the-formatted-value/m-p/299780#M63274</link>
      <description>&lt;P&gt;Your initial data step won't work. Dataset names MUST NOT start with a dot.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 08:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Display-the-formatted-value/m-p/299780#M63274</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-21T08:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Display the formatted value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Display-the-formatted-value/m-p/299781#M63275</link>
      <description>&lt;P&gt;And a do statement must be terminated with a semicolon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is always helpful to run the code that shall go into a macro without the macro definition first, to check that you get correct SAS code with the supplied parameters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA COUNTRY;
input country $25.;
CARDS;
INDIA
INDIA
INDIA
INDIA
SPAIN
SPAIN
SPAIN
SPAIN
GERMANY
GERMANY
GERMANY
GERMANY
;
run;

*%macro Country_Check (indsn=, variable=, outdsn=,freq=);
%let indsn=country;
%let variable=country;
%let outdsn=want1;
%let freq=4;


PROC SORT DATA=&amp;amp;indsn;
by &amp;amp;variable;
run;

PROC FREQ DATA=&amp;amp;indsn;
TABLES &amp;amp;variable / noprint out=counts (KEEP=&amp;amp;variable count);
run;

proc format;
value $city 'INDIA'='ASIA'
'GERMANY'='EUROPE'
'SPAIN'='EUROPE'
'BELGIUM'='EUROPE'
'FRANCE'='EUROPE'
other='UNKNOWN';
run;

data &amp;amp;outdsn;
MERGE &amp;amp;indsn counts;
By &amp;amp;variable;
if count &amp;lt;= &amp;amp;Freq then do;
newvar= put(&amp;amp;variable, $city.);
end;
DROP count;
run;
proc print data = &amp;amp;outdsn; run;
*%MEND Country_Check;

*%Country_Check (indsn=myfile.COUNTRY, variable=country, outdsn=want1, Freq=4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will work. You can proceed from there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 08:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Display-the-formatted-value/m-p/299781#M63275</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-21T08:48:01Z</dc:date>
    </item>
  </channel>
</rss>

