<?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: SAS Formats in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242132#M55774</link>
    <description>&lt;P&gt;Here's a partial workaround.&amp;nbsp; Define two formats, one based on the entire ID, and a second based on 3 characters.&amp;nbsp; Be sure to include the OTHER= category.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;value $Client '2BCD' = 'A'&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; '2ACD' = 'B'&lt;/P&gt;
&lt;P&gt;other=' ';&lt;/P&gt;
&lt;P&gt;value $sub '2CD' = 'C'&lt;/P&gt;
&lt;P&gt;other=' ';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can use a DATA step that is only slightly longer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;client = put(account_ID, $client.);&lt;/P&gt;
&lt;P&gt;if client=' ' then client=put( substr(account_id, 1, 3), $sub.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jan 2016 22:04:39 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-01-06T22:04:39Z</dc:date>
    <item>
      <title>SAS Formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242128#M55773</link>
      <description>&lt;P&gt;I have various values that I want to assign formats to. However, some of these values are substrings. For example, say I have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if AccountID = '2BCD' then Client = 'A';&lt;/P&gt;&lt;P&gt;else if AccountID = '2ACD' then Client = 'B';&lt;/P&gt;&lt;P&gt;else if substr(AccountID,1,3) = '2CD' then Client = 'C';&lt;/P&gt;&lt;P&gt;else if...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, instead of having a ton of if else statements I want to assign a format called $Client. to the variable Client. So, I would do the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;value $Client '2BCD' = 'A'&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'2ACD' = 'B'&lt;/P&gt;&lt;P&gt;this is where I get stuck because I cannot simply say '2CD' = 'C' because it is only a substring of the AccountID.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 21:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242128#M55773</guid>
      <dc:creator>rsulliv3</dc:creator>
      <dc:date>2016-01-06T21:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242132#M55774</link>
      <description>&lt;P&gt;Here's a partial workaround.&amp;nbsp; Define two formats, one based on the entire ID, and a second based on 3 characters.&amp;nbsp; Be sure to include the OTHER= category.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;value $Client '2BCD' = 'A'&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; '2ACD' = 'B'&lt;/P&gt;
&lt;P&gt;other=' ';&lt;/P&gt;
&lt;P&gt;value $sub '2CD' = 'C'&lt;/P&gt;
&lt;P&gt;other=' ';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can use a DATA step that is only slightly longer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;client = put(account_ID, $client.);&lt;/P&gt;
&lt;P&gt;if client=' ' then client=put( substr(account_id, 1, 3), $sub.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 22:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242132#M55774</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-06T22:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242137#M55775</link>
      <description>&lt;P&gt;This might be case for a multilabel format. If you use the format with anything except proc tabulate or report while specifying use of the multilabel then the result could well be what you want. Used with a Put assignment such as Client = put(accountid,$clients.) you will get the top label only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library=work;
value $clients (multilabel)
'2BCD' = 'A'
'2ACD' = 'B'
'2CDA','2CDB','2CDC'= 'C'
'2CDA'= "C: Branch A"
'2CDB'= "C: Branch B"
'2CDC'= "C: Branch C"
;
run;

Data have;
input branch $ amount;
datalines;
2BCD  501
2ACD  300
2CDA  400
2CDB  600
2CDC  800
;
RUN;

proc freq data=have;
   tables branch;
   format branch $clients.;
run;

proc tabulate data=have;
   class branch / mlf;
   var amount;
   format branch $clients.;
   table branch, amount*sum;
run;

proc print data=have;
format branch $clients.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jan 2016 23:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242137#M55775</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-01-06T23:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242141#M55776</link>
      <description>&lt;P&gt;I would use PROC FCMP to define the desired format $Client (requires SAS 9.3 or higher).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.funcs.test;
function accfmt(AccountID $) $;
  length Client $20; /* Please adapt the length to your needs! */

  if AccountID = '2BCD' then Client = 'A';
  else if AccountID = '2ACD' then Client = 'B';
  else if substr(AccountID,1,3) = '2CD' then Client = 'C';
  /* else if ... */

  return(Client);
endsub;
quit;

options cmplib=work.funcs;

proc format;
value $Client (default=20) /* replace 20 by the length of variable CLIENT above */
other=[accfmt()];
run;

/* Test */

data _null_;
input AccountID $;
put AccountID $Client.;
cards;
2BCD
2ACD
2CDX
2CDY
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 00:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242141#M55776</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-07T00:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242172#M55779</link>
      <description>&lt;P&gt;An alternative to formats, which can be helpful in certain circumstances is to use datasets. &amp;nbsp;The example below shows the ability to generate any form of code to apply a codelist to a value. &amp;nbsp;(Note the code here is only for the substr() example given, if its more complicated then you might need to add more code):&lt;/P&gt;
&lt;PRE&gt;data have;&lt;BR /&gt; input account_id $10.;&lt;BR /&gt;datalines;&lt;BR /&gt;2BCD&lt;BR /&gt;2ACD&lt;BR /&gt;AA2CDBB&lt;BR /&gt;2CDERT&lt;BR /&gt;ABCD&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data codelist;&lt;BR /&gt; length code long_value $10 logic $50;&lt;BR /&gt; code="2BCD"; long_value="A"; logic="account_id"; output;&lt;BR /&gt; code="2ACD"; long_value="B"; logic="account_id"; output;&lt;BR /&gt; code="2CD"; long_value="C"; logic="substr(account_id,1,3)"; output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* This is where the code is generated */&lt;BR /&gt;data _null_;&lt;BR /&gt; set codelist end=last;&lt;BR /&gt; if _n_=1 then call execute('data have; set have; length long_value $10;');&lt;BR /&gt; call execute(' if '||strip(logic)||'="'||strip(code)||'" then long_value="'||strip(long_value)||'";');&lt;BR /&gt; if last then call execute('run;');&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jan 2016 10:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Formats/m-p/242172#M55779</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-07T10:05:45Z</dc:date>
    </item>
  </channel>
</rss>

