<?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: User defined format from reference SQL table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585709#M167100</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;May I know how can I create the look up table?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Once again, Maxim 1: Read the Documentation.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=p0owa4ftikc2ekn1q0rmpulg86cx.htm&amp;amp;locale=en#p05g1cdvff8h8tn1frtzxrnkzezo" target="_blank" rel="noopener"&gt;Input Control Data Set&lt;/A&gt; in &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=p1xidhqypi0fnwn1if8opjpqpbmn.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;PROC FORMAT&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need 5 variables:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;fmtname - name of the format&lt;/LI&gt;
&lt;LI&gt;type - 'C' for character, 'N' for numeric&lt;/LI&gt;
&lt;LI&gt;start - the value to be formatted&lt;/LI&gt;
&lt;LI&gt;label - the formatted value&lt;/LI&gt;
&lt;LI&gt;hlo - set to 'O' in an observation that covers all other values&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Sep 2019 06:45:07 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-09-03T06:45:07Z</dc:date>
    <item>
      <title>User defined format from reference SQL table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585627#M167045</link>
      <description>There is a variable called Entity_Id in SAS dataset and for that variable I have to apply the format where the format is located in the SQL table. I don't want to create the SAS dataset of that SQL table.&lt;BR /&gt;&lt;BR /&gt;How can I apply the format from SQL to SAS?</description>
      <pubDate>Mon, 02 Sep 2019 15:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585627#M167045</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-02T15:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: User defined format from reference SQL table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585630#M167048</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;There is a variable called Entity_Id in SAS dataset and for that variable I have to apply the format where the format is located in the SQL table. I don't want to create the SAS dataset of that SQL table.&lt;BR /&gt;&lt;BR /&gt;How can I apply the format from SQL to SAS?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You will either need to explain better and/or provide a concrete example.&lt;/P&gt;
&lt;P&gt;What do you mean by "apply the format" to ENTITY_ID?&amp;nbsp; Do you mean use a format to convert the values of ENTITY_ID into some other text?&lt;/P&gt;
&lt;P&gt;What is an "SQL table"? How is that different than a SAS dataset?&amp;nbsp; Are you querying some external database?&amp;nbsp; If so how are you going to use information from that external database without reading it?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2019 15:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585630#M167048</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-02T15:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: User defined format from reference SQL table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585635#M167050</link>
      <description>Yes, I want to apply the format to convert the values of Entity_ID to some&lt;BR /&gt;other text.&lt;BR /&gt;&lt;BR /&gt;Yes, I want to query the external database.&lt;BR /&gt;&lt;BR /&gt;Below example is the data which I have in external database (sql server) as&lt;BR /&gt;a table.Right now I have the variable  in SAS with old_entity_id and I want&lt;BR /&gt;to convert it into new_entity_id&lt;BR /&gt;&lt;BR /&gt;E.g.&lt;BR /&gt;&lt;BR /&gt;New_Entity_id  Old_entity_id&lt;BR /&gt;1234                   12345&lt;BR /&gt;6789                    67890&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Sep 2019 16:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585635#M167050</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-02T16:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: User defined format from reference SQL table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585637#M167052</link>
      <description>&lt;P&gt;You could use the values from that external table to define a format.&amp;nbsp; Assuming you have made a libref MYSQLLIB that points to your database/schema and the mapping data is in a table named MY_MAPPING_TABLE.&amp;nbsp; Also assuming the ENTITY_ID is a character string (why would you use a number for something you would never want to do arithmetic with?) then code might look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table fmt as
select distinct
      '$new_entity_id' as fmtname
     , old_entity_id as start
     , new_entity_id as label
from mysqllib.my_mapping_table
order by 1,2
;
quit;
proc format cntlin=fmt; run;
data want ;
  set have ;
  new_entity_id = put(entity_id,$new_entity_id.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you cannot define a format in SAS without actually reading the data that defines it into SAS.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the source table is large and the SAS table that has the values that need mapping is small it might be fastest to just pull the values you need from the external database.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2019 17:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585637#M167052</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-02T17:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: User defined format from reference SQL table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585680#M167079</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt; I don't want to create the SAS dataset of that SQL table.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;You'll have to&amp;nbsp;unfortunately, or at minimum create the lookup table.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 02:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585680#M167079</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-03T02:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: User defined format from reference SQL table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585702#M167096</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I don't want to create the SAS dataset of that SQL table.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then use a view. But since cntlin datasets are quite small by nature (only 5 columns needed), there's no need to avoid building the input data as a dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 05:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585702#M167096</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-03T05:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: User defined format from reference SQL table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585704#M167097</link>
      <description>May I know how can I create the look up table?&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Sep 2019 05:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585704#M167097</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-03T05:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: User defined format from reference SQL table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585709#M167100</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;May I know how can I create the look up table?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Once again, Maxim 1: Read the Documentation.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=p0owa4ftikc2ekn1q0rmpulg86cx.htm&amp;amp;locale=en#p05g1cdvff8h8tn1frtzxrnkzezo" target="_blank" rel="noopener"&gt;Input Control Data Set&lt;/A&gt; in &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=p1xidhqypi0fnwn1if8opjpqpbmn.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;PROC FORMAT&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need 5 variables:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;fmtname - name of the format&lt;/LI&gt;
&lt;LI&gt;type - 'C' for character, 'N' for numeric&lt;/LI&gt;
&lt;LI&gt;start - the value to be formatted&lt;/LI&gt;
&lt;LI&gt;label - the formatted value&lt;/LI&gt;
&lt;LI&gt;hlo - set to 'O' in an observation that covers all other values&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 06:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585709#M167100</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-03T06:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: User defined format from reference SQL table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585812#M167153</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;May I know how can I create the look up table?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Same way you reference any other table, Tom's code is correct, assuming we've interpreted your question correctly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 13:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/User-defined-format-from-reference-SQL-table/m-p/585812#M167153</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-03T13:11:56Z</dc:date>
    </item>
  </channel>
</rss>

