Desktop productivity for business analysts and programmers

length and value of character variable..

Reply
N/A
Posts: 0

length and value of character variable..

data abc;
address1='201 London fly';
run;
data abc;
set abc;
address=tranwrd(address1,'fly','drive');
run;


ques: what will be the length and value of variable 'address' in data set abc;

in notes i found answer like length=200 and value is '201 London drive'.....please ensure it is right...what you think abt the answer..tell me
Regular Contributor
Posts: 234

Re: length and value of character variable..

Reading the online documentation for the transwrd function I found two import sentences:
"If the TRANWRD function returns a value to a variable that has not yet been assigned a length, by default the variable is assigned a length of 200."
and
"The value that the TRANWRD function returns has a default length of 200. You can use the LENGTH statement, before calling TRANWRD, to change the length of the value."
Senior User
Posts: 1

Re: length and value of character variable..

While running the following program, the result from  proc print & proc content:  for  'address' length is 200 & value is '201 London drive' as well as for 'address1' length is 14 & value is '201 London fly'.

 

data abc;
address1='201 London fly';
run;
data abc;
set abc;
address=tranwrd(address1,'fly','drive');
run;

proc print data=abc;
run;
proc contents data=abc;
run;

 

 

 

SAS Output

Obs address1 address 1
201 London fly201 London drive

 

SAS Output

Alphabetic List of Variables and Attributes # Variable Type Len 2 1
addressChar200
address1Char14
Ask a Question
Discussion stats
  • 2 replies
  • 692 views
  • 0 likes
  • 3 in conversation