BookmarkSubscribeRSS Feed
clqa
Calcite | Level 5

does length(“ “)=1? when do you use the length statement versus length('string')?

 

is “ the same thing as ‘ in SAS?

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@clqa wrote:

does length(“ “)=1?


You can find the answer by simply trying this in SAS.

 

when do you use the length statement versus length('string')?

 

Length function tells you the length of a string; length statement sets the length of a variabel

 

is “ the same thing as ‘ in SAS?

 

If you are writing macros or using macro variables or macro functions/commands, then double-quote is not the same as single-quote. Otherwise, with no macro language, double quote is the same as single-quote.

--
Paige Miller
ballardw
Super User

@clqa wrote:

does length(“ “)=1? when do you use the length statement versus length('string')?

 

 


Length statement and Length function are different. One sets the maximum number of bytes a variable used for storage, 3 to 8 in the case of numeric variables, which may limit the precision of storage and calculations of those variables, or 1 to quite a bit longer for character variables.

 

data junk;
   x= ' ';
   y= ' d';
   z= 'd ';
   length q $ 25;
   q='';
   lx=length(x);
   ly=length(y);
   lz=length(z);
   lq=length(q);
run;

is “ the same thing as ‘ in SAS?


In this specific case very most definitely not. Whether they occurred from typing or copy and paste neither of those actual characters are a good idea.

 “    ‘ 
 "    '

The top row above are the characters you typed or ended up in the post for the question. The characters used in programming are on the second row. The top row are often referred to as "smart quotes" as they look more typeset. However they will generally yield errors when used in programming. And one of the reasons we strongly recommend posting and code into the code box the forum opens with the {I} icon. The main message windows will quite often reformat text in a number of ways. Some will yield code that will not run, others change values.

 

ChrisNZ
Tourmaline | Level 20

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 631 views
  • 2 likes
  • 4 in conversation