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
Ammonite | Level 13

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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 856 views
  • 3 likes
  • 5 in conversation