<?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 Can PROC FORMAT create a null formatted value rather than blank? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897691#M354770</link>
    <description>&lt;P&gt;Is it possible to use PROC FORMAT to create a null formatted value&amp;nbsp;so that the formatted value is nothing (not a blank)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both of these store a blank as the formatted value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
 value $foo
  "blank"=" "
  "null"="00"x 
 ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;9    %put &amp;gt;&amp;gt;%sysfunc(putc(blank,$foo))&amp;lt;&amp;lt; ;
&amp;gt;&amp;gt; &amp;lt;&amp;lt;
10   %put &amp;gt;&amp;gt;%sysfunc(putc(null,$foo))&amp;lt;&amp;lt; ;
&amp;gt;&amp;gt; &amp;lt;&amp;lt;
&lt;/PRE&gt;
&lt;P&gt;I want a null string, which would be nice if could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
 value $foo
  "null"="" /*does not work, the value becomes a double quote*/
 ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If I can't get a null string, I can deal with it by using trimn(), e.g.:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;11   %put &amp;gt;&amp;gt;%sysfunc(trimn(%sysfunc(putc(blank,$foo))%str( )))&amp;lt;&amp;lt; ;
&amp;gt;&amp;gt;&amp;lt;&amp;lt;
&lt;/PRE&gt;
&lt;P&gt;But I wonder if I'm missing an obvious way to have a format definition store a null formatted value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 07 Oct 2023 22:08:10 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-10-07T22:08:10Z</dc:date>
    <item>
      <title>Can PROC FORMAT create a null formatted value rather than blank?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897691#M354770</link>
      <description>&lt;P&gt;Is it possible to use PROC FORMAT to create a null formatted value&amp;nbsp;so that the formatted value is nothing (not a blank)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both of these store a blank as the formatted value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
 value $foo
  "blank"=" "
  "null"="00"x 
 ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;9    %put &amp;gt;&amp;gt;%sysfunc(putc(blank,$foo))&amp;lt;&amp;lt; ;
&amp;gt;&amp;gt; &amp;lt;&amp;lt;
10   %put &amp;gt;&amp;gt;%sysfunc(putc(null,$foo))&amp;lt;&amp;lt; ;
&amp;gt;&amp;gt; &amp;lt;&amp;lt;
&lt;/PRE&gt;
&lt;P&gt;I want a null string, which would be nice if could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
 value $foo
  "null"="" /*does not work, the value becomes a double quote*/
 ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If I can't get a null string, I can deal with it by using trimn(), e.g.:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;11   %put &amp;gt;&amp;gt;%sysfunc(trimn(%sysfunc(putc(blank,$foo))%str( )))&amp;lt;&amp;lt; ;
&amp;gt;&amp;gt;&amp;lt;&amp;lt;
&lt;/PRE&gt;
&lt;P&gt;But I wonder if I'm missing an obvious way to have a format definition store a null formatted value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2023 22:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897691#M354770</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-10-07T22:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Can PROC FORMAT create a null formatted value rather than blank?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897692#M354771</link>
      <description>&lt;P&gt;Just hit submit, then realized this works (but also seems silly).&amp;nbsp; Assign a macro variable reference as the formatted value, and assign a null value to the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value $foo
    "null"='&amp;amp;null'
  ;
run ;
%let null= ;
%put &amp;gt;&amp;gt;%sysfunc(putc(null,$foo))&amp;lt;&amp;lt; ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then that led me to this, which I'm starting to like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value $foo
    "null"='%str()'  /*must be single quotes*/
  ;
run ;
%put &amp;gt;&amp;gt;%sysfunc(putc(null,$foo))&amp;lt;&amp;lt; ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Oct 2023 22:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897692#M354771</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-10-07T22:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Can PROC FORMAT create a null formatted value rather than blank?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897694#M354772</link>
      <description>&lt;P&gt;But perhaps I'm stuck with using TRIMN or some alternative for trimming blanks.&amp;nbsp; Since the format itself has a fixed with, if I have another formatted value that is longer than six characters, I'll still get trailing blanks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value $foo   
    'A'='Some long text'
    'null'='%str()'
  ;
run ;
%put &amp;gt;&amp;gt;%sysfunc(putc(null,$foo))&amp;lt;&amp;lt; ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2023 22:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897694#M354772</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-10-07T22:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Can PROC FORMAT create a null formatted value rather than blank?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897695#M354773</link>
      <description>&lt;P&gt;I doubt it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the use case for this format?&amp;nbsp; Why not just use logic instead?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only format that can generate zero length string is $VARYING, but I don't think you can use that with PUT() function, only PUT statement.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input string $20. ;
  len = lengthn(string) * (string ne 'null');
  put string $varying10. len @;
cards;
String1
String2
 
String4
null
String5
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;694  data test;
695    input string $20. ;
696    len = lengthn(string) * (string ne 'null');
697    put string $varying10. len @;
698  cards;

String1String2String4String5
NOTE: The data set WORK.TEST has 6 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


705  ;
&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Oct 2023 01:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897695#M354773</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-08T01:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can PROC FORMAT create a null formatted value rather than blank?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897697#M354774</link>
      <description>&lt;P&gt;You could do it as below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $foo (default=10)
    'blank'=' '
  ;
run;

%let val=%sysfunc(putc(blank,$foo));
%put &amp;gt;&amp;gt;&amp;amp;val&amp;lt;&amp;lt;;
%let val=%sysfunc(putc(some text,$foo));
%put &amp;gt;&amp;gt;&amp;amp;val&amp;lt;&amp;lt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1696728607549.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88709i963907FABA69CE26/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1696728607549.png" alt="Patrick_0-1696728607549.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2023 01:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897697#M354774</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-08T01:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Can PROC FORMAT create a null formatted value rather than blank?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897805#M354842</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;, yes, using the fact the %LET ignores leading and trailing blanks is another way to strip blanks.&amp;nbsp; My curiosity was whether was a way to have the format actually return a null string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use case was basically making a report where the title includes information about an ID, some IDs have optional parenthetical information.&amp;nbsp; Something like:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value idinfo 
    1=' (text info - ID1)'
    2=' '
    3='%str()%str()%str()'
  ;
run ;

title1 "ID 1%sysfunc(putn(1,idinfo)) enrolled..." ;
title2 "ID 2%sysfunc(putn(2,idinfo)) enrolled..." ;
title3 "ID 3%sysfunc(putn(3,idinfo)) enrolled..." ;

proc sql ;
  select * from sashelp.vtitle ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because of the PUT statement returning a fixed length string, you get the unwanted blanks for ID 2:&lt;/P&gt;
&lt;PRE&gt;ID 1 (text info - ID1) enrolled...
ID 2                   enrolled...
ID 3 enrolled...
&lt;/PRE&gt;
&lt;P&gt;But while my idea of using %STR() is perhaps amusing, it's not very practical, as it only 'works' if every formatted value is exactly the same length.&amp;nbsp; So for my use case I'll probably stick with TRIM(), since it makes the purpose explicit. Obviously there are plenty of ways to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course in a DATA step there is no such thing as a null string, since character variables are padded with blanks.&amp;nbsp; So it's not surprising that a format wouldn't be designed to return a null value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 12:36:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-PROC-FORMAT-create-a-null-formatted-value-rather-than-blank/m-p/897805#M354842</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-10-09T12:36:40Z</dc:date>
    </item>
  </channel>
</rss>

