BookmarkSubscribeRSS Feed
CharlotteCain
Quartz | Level 8

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

4 REPLIES 4
MadhuKorni
Quartz | Level 8

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

CharlotteCain
Quartz | Level 8

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?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 5454 views
  • 2 likes
  • 3 in conversation