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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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