<?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: Appying two formats to a variable based on another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Appying-two-formats-to-a-variable-based-on-another-variable/m-p/446308#M283230</link>
    <description>Thanks Reeza &amp;amp; Tom for your quick replies! I figured I was going to have to create another variable and you confirmed that for me. I very much appreciate your examples. That is exactly what I'll use. Thanks again.</description>
    <pubDate>Fri, 16 Mar 2018 19:11:29 GMT</pubDate>
    <dc:creator>whateverwhateve</dc:creator>
    <dc:date>2018-03-16T19:11:29Z</dc:date>
    <item>
      <title>Appying two formats to a variable based on another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appying-two-formats-to-a-variable-based-on-another-variable/m-p/446300#M283227</link>
      <description>&lt;P&gt;I have one variable that's values are either 'state' of 'country'. State meaning its a state in the united states. Country meaning it is outside of the united states.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My second variables values are state or country codes. This is the variable I want to format with two different formats based on what my first variable is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, if my first variable has a value of 'state' then I want to apply my state format to the second variable. And if my first variable has a value of 'country' then I want to apply my country format to the second variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an example, if my first variable has a value of 'state' and my second variable has a value of 'TX' then the state format would make that value in my second variable read 'TEXAS'. But if &amp;nbsp;first variable has a value of 'country' and my second variable has a value of 'TX' then the&amp;nbsp;country format would make that value in my second variable read 'TURKMENISTAN'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this next line of code is incorrect but I think it tells you what I'm trying to do&lt;/P&gt;&lt;P&gt;if var1='state' then&amp;nbsp;var2 $state. else&amp;nbsp;var2 $country.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using Enterprise Guide 7.1&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Kelli&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 18:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appying-two-formats-to-a-variable-based-on-another-variable/m-p/446300#M283227</guid>
      <dc:creator>whateverwhateve</dc:creator>
      <dc:date>2018-03-16T18:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Appying two formats to a variable based on another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appying-two-formats-to-a-variable-based-on-another-variable/m-p/446301#M283228</link>
      <description>&lt;P&gt;I think you’ll need to create a new variable in this case with the formatted value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if var1=‘state’ then desc = putc(var2, ‘$state_fmt’);&lt;/P&gt;
&lt;P&gt;else desc = putc(var2, ‘$country_fmt’);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 18:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appying-two-formats-to-a-variable-based-on-another-variable/m-p/446301#M283228</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-16T18:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Appying two formats to a variable based on another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appying-two-formats-to-a-variable-based-on-another-variable/m-p/446303#M283229</link>
      <description>&lt;P&gt;You can't do that.&amp;nbsp; No more than you have some observations where the variable is numeric and others where the same variable is character.&amp;nbsp; The format attached to a variable is an attribute of the variable, not of a particular observation.&amp;nbsp;&amp;nbsp;You will need to create a new variable to hold the decoded value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you have data like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  length code $10 code_type $10 ;
  input code code_type ;
cards;
TX state
USA country
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have formats named $STATE and $COUNTRY you could even just use the value of CODE_TYPE to generate the format to use.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  length description $100 ;
  description=putc(code,cats('$',code_type,'.'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Mar 2018 18:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appying-two-formats-to-a-variable-based-on-another-variable/m-p/446303#M283229</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-16T18:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Appying two formats to a variable based on another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appying-two-formats-to-a-variable-based-on-another-variable/m-p/446308#M283230</link>
      <description>Thanks Reeza &amp;amp; Tom for your quick replies! I figured I was going to have to create another variable and you confirmed that for me. I very much appreciate your examples. That is exactly what I'll use. Thanks again.</description>
      <pubDate>Fri, 16 Mar 2018 19:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appying-two-formats-to-a-variable-based-on-another-variable/m-p/446308#M283230</guid>
      <dc:creator>whateverwhateve</dc:creator>
      <dc:date>2018-03-16T19:11:29Z</dc:date>
    </item>
  </channel>
</rss>

