this is the code:
data work.test;
First = 'Ipswich, England';
City_Country = substr(First,1,7)!!', '!!'England';
run;
You can run PROC CONTENTS on the data set and find out yourself.
proc contents data=test;
run;
Maxim 4: If in Doubt, Do a Test Run.
Run your code, and inspect the dataset, or run PROC CONTENTS and read the output.
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;
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.
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!
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.