<?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: Dynamically creating formats in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740873#M231513</link>
    <description>And you need CALL EXECUTE() not PUT.</description>
    <pubDate>Wed, 12 May 2021 17:14:37 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-05-12T17:14:37Z</dc:date>
    <item>
      <title>Dynamically creating formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740863#M231508</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am using the following code to dynamically create formats based on a SAS work dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set cd_10_&amp;amp;ODS_dsn end=eof;&lt;BR /&gt;if _n_ = 1 then do;&lt;BR /&gt;put @1 "proc format;";&lt;BR /&gt;put @8 "value $&amp;amp;ODS_dsn";&lt;BR /&gt;end;&lt;BR /&gt;put @8 VariableOID &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/162406"&gt;@20&lt;/a&gt; "= ' "cdval"'";&lt;BR /&gt;if eof then do;&lt;BR /&gt;put @8 ";";&lt;BR /&gt;put @1 "run;";&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code works fine.&amp;nbsp; For example, here is result in the log file.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format;&lt;BR /&gt;value $CMCDB&lt;BR /&gt;CMINDTYP = ' #Coded_Terms!A244 '&lt;BR /&gt;CMONGO = ' #Coded_Terms!A247 '&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;NOTE: There were 2 observations read from the data set WORK.CD_10_CMCDB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I do not see in the log file is a message that the format $CMCDB. has been outputted. When I try to use this format later in the program, the format is not found.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 16:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740863#M231508</guid>
      <dc:creator>cgsmoak56</dc:creator>
      <dc:date>2021-05-12T16:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically creating formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740872#M231512</link>
      <description>Are you familiar with a CNTLIN data set? SAS can create a format from a data set directly. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 12 May 2021 17:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740872#M231512</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-12T17:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically creating formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740873#M231513</link>
      <description>And you need CALL EXECUTE() not PUT.</description>
      <pubDate>Wed, 12 May 2021 17:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740873#M231513</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-12T17:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically creating formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740874#M231514</link>
      <description>&lt;P&gt;Make sure you show us the code you actually use. Best is to copy from the log, the entire proc format and any notes, the paste into a text box opened on the forum with the &amp;lt;/&amp;gt; icon at the top of the message window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The CNTLIN= option uses a standardized data set in Proc Format to create formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code would have to 1) write the code to a text file and then 2) use %include to make that execute.&lt;/P&gt;
&lt;PRE&gt;data _null_;
set cd_10_&amp;amp;ODS_dsn end=eof;
file "&amp;lt;path to file&amp;gt;\makemyformat.sas";
if _n_ = 1 then do;
put @1 "proc format;";
put @8 "value $&amp;amp;ODS_dsn";
end;
put @8 VariableOID @20 "= ' "cdval"'";
if eof then do;
put @8 ";";
put @1 "run;";
end;
run;

%include "&amp;lt;path to file&amp;gt;\makemyformat.sas";&lt;/PRE&gt;
&lt;P&gt;or use "call execute" instead of "put" to place the generated statements into the execution stack.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just "putting" text to the log does not write any actual code that&amp;nbsp; is executed.&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 17:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740874#M231514</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-12T17:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically creating formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740875#M231515</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/357933"&gt;@cgsmoak56&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/357933"&gt;@cgsmoak56&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What I do not see in the log file is a message that the format $CMCDB. has been outputted. When I try to use this format later in the program, the format is not found.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is because you wrote the code to the log (as text), but did not execute it. This can be fixed easily: Write the code to a (e.g., temporary) text file and then submit the content of that file via %INCLUDE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only three statements need to be inserted into your code:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;filename fmtcode temp;&lt;/FONT&gt;&lt;/STRONG&gt;

data _null_;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;file fmtcode;&lt;/STRONG&gt;&lt;/FONT&gt;
&amp;lt;your code&amp;gt;
run;

&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;%include fmtcode / source;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 17:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740875#M231515</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-05-12T17:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically creating formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740877#M231517</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;If you provide your input data set&amp;nbsp;&lt;SPAN&gt;WORK.CD_10_CMCDB (2 records) in a data step with datalines (cards;), I will have a look at your data-driven code generation.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But in general it's better to use the CNTLIN= option to generate a format from a data set.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;See here:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Base SAS Procedures Guide -- FORMAT Procedure&lt;BR /&gt;Example 13: Creating a Format from a CNTLIN= Data Set&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1e19y6lrektafn1kj6nbvhus59w.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1e19y6lrektafn1kj6nbvhus59w.htm&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Good luck,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Koen&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 17:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740877#M231517</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-05-12T17:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically creating formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740887#M231524</link>
      <description>&lt;P&gt;Thank you.&amp;nbsp; This solution worked!&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 17:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740887#M231524</guid>
      <dc:creator>cgsmoak56</dc:creator>
      <dc:date>2021-05-12T17:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically creating formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740889#M231525</link>
      <description>&lt;P&gt;Thank you.&amp;nbsp; That should also work.&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 17:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-creating-formats/m-p/740889#M231525</guid>
      <dc:creator>cgsmoak56</dc:creator>
      <dc:date>2021-05-12T17:50:37Z</dc:date>
    </item>
  </channel>
</rss>

