<?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: Proc format to create a format from a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756636#M238923</link>
    <description>&lt;P&gt;Names of character formats start with $.&lt;/P&gt;
&lt;P&gt;Why do you assign a value to TYPE but then drop the variable?&lt;/P&gt;
&lt;P&gt;Why do you assign a vlaue to HLO but then drop the variable?&lt;BR /&gt;Why do never output the HLO observation?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subject;
  length fmtname $32 type $1 hlo $3 start new_id $12;
  set db.en end=end;
  new_id = substr(usubjid,8,3) || substr(usubjid,4,3) ;
  start = new_id;
  label = usubjid;
  retain fmtname '$SubjectFmt' type 'C';
  output;
  if end then do;
    hlo = 'O' ;
    label = 'ERROR';
    output;
  end;
  *keep fmtname type start label hlo ;
run;

proc format cntlin = subject cntlout = cntlout; run;

proc format library=work fmtlib; select $SubjectFmt; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Jul 2021 14:01:39 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-07-26T14:01:39Z</dc:date>
    <item>
      <title>Proc format to create a format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756541#M238883</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;
&lt;P&gt;Long time programmer here, however, I am stumped!&lt;/P&gt;
&lt;P&gt;Why the heck isn't the format retaining the zeros when I have indicated the format type as 'C'?&amp;nbsp; Here is the code :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; subject(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;keep&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=siteid start label fmtname usubjid new_id);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; new_id $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; db.en &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; new_id = substr(usubjid,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) || substr(usubjid,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;start = new_id;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;label&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; = usubjid;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;retain&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; fmtname &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"SubjectFmt"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; type &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"C"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; end &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;then&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; hlo = &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'O'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;label&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; = &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'ERROR&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;format&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;cntlin&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; = subject &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;cntlout&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; = cntlout; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;format&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;library&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=work; &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SubjectFmt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;attached are exampled of the dataset and the resulting format.&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;NJGirl&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorNJGIRL_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jul 2021 22:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756541#M238883</guid>
      <dc:creator>NJGIRL</dc:creator>
      <dc:date>2021-07-25T22:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format to create a format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756545#M238885</link>
      <description>&lt;P&gt;Is&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;usubjid&lt;/SPAN&gt; &lt;/FONT&gt;a string?&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jul 2021 22:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756545#M238885</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-25T22:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format to create a format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756573#M238906</link>
      <description>&lt;P&gt;Please don't hide information in office-files, many contributors won't open such files. Post data as data step using datalines, and attach screenshots using "insert photos" (the small camera icon). And don't forget to post the log as text using "insert code" so that formatting is maintained.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 06:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756573#M238906</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-07-26T06:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format to create a format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756580#M238909</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/144583"&gt;@NJGIRL&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Why the heck isn't the format retaining the zeros when I have indicated the format type as 'C'?&amp;nbsp; Here is the code :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; subject(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;keep&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=siteid start label fmtname usubjid new_id);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;...&lt;/FONT&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/144583"&gt;@NJGIRL&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add &lt;FONT face="courier new,courier"&gt;type&lt;/FONT&gt; to the KEEP= list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also add the missing quotation mark in&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;label&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; = &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'ERROR&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 07:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756580#M238909</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-07-26T07:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format to create a format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756630#M238922</link>
      <description>Hi ChrisNZ, &lt;BR /&gt;&lt;BR /&gt;It is a character. &lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jul 2021 13:38:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756630#M238922</guid>
      <dc:creator>NJGIRL</dc:creator>
      <dc:date>2021-07-26T13:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format to create a format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756636#M238923</link>
      <description>&lt;P&gt;Names of character formats start with $.&lt;/P&gt;
&lt;P&gt;Why do you assign a value to TYPE but then drop the variable?&lt;/P&gt;
&lt;P&gt;Why do you assign a vlaue to HLO but then drop the variable?&lt;BR /&gt;Why do never output the HLO observation?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subject;
  length fmtname $32 type $1 hlo $3 start new_id $12;
  set db.en end=end;
  new_id = substr(usubjid,8,3) || substr(usubjid,4,3) ;
  start = new_id;
  label = usubjid;
  retain fmtname '$SubjectFmt' type 'C';
  output;
  if end then do;
    hlo = 'O' ;
    label = 'ERROR';
    output;
  end;
  *keep fmtname type start label hlo ;
run;

proc format cntlin = subject cntlout = cntlout; run;

proc format library=work fmtlib; select $SubjectFmt; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jul 2021 14:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756636#M238923</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-26T14:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc format to create a format from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756648#M238930</link>
      <description>THANKS SO MUCH TOM. YOU ARE VERY GOOD AT QUICKLY REVIEWING CODE AND SEEING THE OBVIOUS:() &lt;BR /&gt;&lt;BR /&gt;(I guess the answer to your questions would be this:  I was staring at it  for way too long and couldn't see beyond the weeds. got way too wrapped up it. This happens to me when I stare at code for hours and hours every day!!   PHEW.:) &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 26 Jul 2021 14:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-format-to-create-a-format-from-a-dataset/m-p/756648#M238930</guid>
      <dc:creator>NJGIRL</dc:creator>
      <dc:date>2021-07-26T14:44:53Z</dc:date>
    </item>
  </channel>
</rss>

