BookmarkSubscribeRSS Feed
AnkitaSingh_901
Calcite | Level 5

this is the code:

 

data work.test;
First = 'Ipswich, England';
City_Country = substr(First,1,7)!!', '!!'England';
run;

5 REPLIES 5
PaigeMiller
Diamond | Level 26

You can run PROC CONTENTS on the data set and find out yourself.

 

proc contents data=test;
run;
--
Paige Miller
SASJedi
SAS Super FREQ

Try the LENGTH function:

data work.test;
	First = 'Ipswich, England';
	City_Country = substr(First,1,7)!!', '!!'England';
	HowLong=length(City_Country);
	put "NOTE: City_Country is " HowLong "characters long.";
run;
Check out my Jedi SAS Tricks for SAS Users
AnkitaSingh_901
Calcite | Level 5
i did that.. its showing length is 25. But i am not able to understand how??
Tom
Super User Tom
Super User

That will show how long the value stored is CITY_COUNTRY is.  To see how long the variable is you need to use VLENGTH() function instead.

data work.test;
  First = 'Ipswich, England';
  City_Country = substr(First,1,7)!!', '!!'England';

  HowLong = vlength(First);
  put 'NOTE: First can hold ' howlong 'bytes.';
  HowLong = vlength(city_country);
  put 'NOTE: City_Country can hold ' howlong 'bytes.';

  HowLong=length(City_Country);
  put 'NOTE: "' City_Country $varying100. howlong '" is ' HowLong 'bytes long.';
run;

The reason that CITY_COUNTRY is defined to be able to hold 25 bytes is that is the GUESS that SAS made about what the maximum length string could have been generated by assignment statement where it first appeared.  16 bytes is the maximum length for FIRST and then you are appending 9 additional bytes. 16+9=25.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 674 views
  • 3 likes
  • 5 in conversation