Hello, What is the difference between $w. informat and $charw. informat? Does it have different functionality? To me it seems $w. works fine reading a character value and I just can't undertsand the $charw.. Please help. Thanks
1.If there is a period in the input field, which is declared as $charw. informat then the period is assigned as a value to the input field
where as in case of $w. the period is stored as blank.
2.One more difference is $charw. wont trim the leading blank spaces where as $w. will trim the leading blank spaces
1.
data charw;
input char $char5.;
cards;
char
.
;
proc print;run;
Output:
1 | char |
---|---|
2 | . |
data w;
input w $5.;
cards;
char
.
;
proc print;run;
Output:
1 | char |
---|---|
2 |
2.
data charw;
input char $char8.;
call symput("char",char);
cards;
char
;
data w;
input w $8.;
call symput("w",w);
cards;
char
;
In the above two datasets there are 3 blank spaces before the value "char"
%put charw usage - There will be blank spaces after abc : abc&char;
%put w usage - There wont be any blank spaces after abc : abc&w;
Output :
%put charw usage - There will be blank spaces after abc : abc&char;
charw usage - There will be blank spaces after abc : abc char
%put w usage - There wont be any blank spaces after abc : abc&w;
w usage - There wont be any blank spaces after abc : abcchar
Hi,
Its in the online documentation:
Comparisons |
The $w. informat is almost identical to the $CHARw. informat. However, $CHARw. does not trim leading blanks nor does it convert a single period in an input field to a blank, while $w. does both.
Hi Robert, Sorry to waste your time, and yes that's the part I am finding it difficult to understand. Trim leading blanks. For a blind eye, does SAS pad blanks per byte? I am not getting the notion of recognising a leading or trailing blank. I would like to visualise an image.
the following test
data j;
a=' ';
a1='';
k=length(a);
k1=length(a1);
run;
length results are the same. Where am i lacking?
Ah yes. Some functions for instance, take length() will return 1 on empty strings. Lengthn() for the same one will return 0. Same with these, an empty string within $char, will have one " " space character, where $w will not="". They are useful in specific circumstances. TBH in 99% of the time your likely to want to see "" rather than " ", which is why I can't remember ever using $char.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.