- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
what is the difference between $4. and $char4. formats in sas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
From the online help for $charw. format:
Comparisons
The $CHARw. format is identical to the $w. format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @ballardw,
I looked up the $charw. format in the documentation and found the below. Would you mind sharing the link are you using?
Thanks & kind regards,
Amir.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Amir wrote:
Hi @ballardw,
I looked up the $charw. format in the documentation and found the below. Would you mind sharing the link are you using?
Thanks & kind regards,
Amir.
That was from my local 9.4.4 online help. Apparently they changed it sometime after that in the documentation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I suspect you found this definition.
Which appears to almost be a copy of the definition of the INFORMAT named $CHAR.
The only actual difference between $ and $CHAR as formats is when you include the $CHAR. format specification (without any WIDTH included) in the PUT statement. There the $CHAR format behaves differently from the $ format in two ways:
- You cannot do the same think with the $ format as you cannot use it without a WIDTH included.
- The leading and trailing spaces are written.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Tom wrote:
- You cannot do the same think with the $ format as you cannot use it without a WIDTH included.
You could use the alias $Fw. to omit the width specification. (I wouldn't regard the single dollar sign in a PUT statement as a format specification. It supports list PUT.) But even $F. does not trim trailing blanks (at least in my SAS 9.4M5). I think the behavior of the two formats has not changed since SAS 6 (why should it?) and the newly added statement in the documentation about $w. and trailing blanks seems just wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There is not much difference between the FORMATs of $ and $CHAR.
1 data test ; 2 x=' X'; 3 put '|' x $4. '|' 4 / '|' x $char4. '|' 5 ; 6 run; | X| | X|
There is a difference in how the INFORMATs of $ and $CHAR behave. The $CHAR informat will preserve the leading spaces.
data test ;
input @1 x $char4. @1 y $4. ;
put (x y) (= $quote.);
cards;
4
34
234
1234
;
1 data test ; 2 input @1 x $char4. @1 y $4. ; 3 put (x y) (= $quote.); 4 cards; x=" 4" y="4" x=" 34" y="34" x=" 234" y="234" x="1234" y="1234"
I suspect that the $CHAR format only exists so you could use a FORMAT name that matches the INFORMAT name you used when creating the variable. Just like we frequently see code posted here (and even included in code generated by SAS) that use BEST as if it was an INFORMAT.