Differences between $w. informat and $charw. informat?

Reply
Frequent Contributor
Posts: 137

Differences between $w. informat and $charw. informat?

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

Contributor
Posts: 65

Re: Differences between $w. informat and $charw. informat?

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:

1char
2.


data w;

input w $5.;

cards;

char

.

;


proc print;run;


Output:

1char
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

Super User
Super User
Posts: 7,392

Re: Differences between $w. informat and $charw. informat?

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.

Frequent Contributor
Posts: 137

Re: Differences between $w. informat and $charw. informat?

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?

Super User
Super User
Posts: 7,392

Re: Differences between $w. informat and $charw. informat?

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.

Ask a Question
Discussion stats
  • 4 replies
  • 766 views
  • 0 likes
  • 3 in conversation