BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Nietzsche
Lapis Lazuli | Level 10

Hi, I am doing Programming 2 lesson 5 on Concatenating tables.

In the video, it says that we can change the length of an attribute by using LENGTH statement prior to the SET statement. 

Nietzsche_0-1666728953820.png

However after running the following code, the length of Name variable is still 8, not 9.

data class_current;
	length Name $9;
    set sashelp.class pg2.class_new2 (rename=(Student=Name));
run;

proc contents data=sashelp.class;
run;

proc contents data=pg2.class_new2;
run;

Nietzsche_2-1666729305143.png

 

did I misunderstand the instructor or did I do something wrong in the code?

 

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

You are changing the length of NAME in the dataset CLASS_CURRENT not SASHELP.CLASS.

View solution in original post

5 REPLIES 5
SASKiwi
PROC Star

You are changing the length of NAME in the dataset CLASS_CURRENT not SASHELP.CLASS.

Nietzsche
Lapis Lazuli | Level 10

thanks man.

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
Nietzsche
Lapis Lazuli | Level 10

another question I have is

How come there is no period after the 9 in the LENGTH statement? Since we are specifying a formatting attribute, should it have a period or period is only necessary in the FORMAT statement?

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
SASKiwi
PROC Star

You don't use periods in LENGTH statements as you are only defining how many bytes a variable is stored in. A period is used in FORMAT and INFORMAT definitions to specify the boundary between the number of digits or characters to be displayed / inputted and the number of decimals for a numeric format.

Tom
Super User Tom
Super User

@Nietzsche wrote:

another question I have is

How come there is no period after the 9 in the LENGTH statement? Since we are specifying a formatting attribute, should it have a period or period is only necessary in the FORMAT statement?


The LENGTH statement is NOT attaching a FORMAT (nor an INFORMAT) to the variable.  It is defining how many bytes the dataset should use to store the value.   The LENGTH statement only accepts integer values so there is no need to include a decimal point in the value.  (Note it will ignore a period if you add one, but don't add one.)

 

The period in a FORMAT or an INFORMAT specification serves two purposes.  It separates the width of the format (or informat) from the optional number of decimal places.   It also makes it so that SAS knows that you mean a FORMAT or INFORMAT and not a variable name.  Otherwise how could SAS parse the FORMAT statement?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 5 replies
  • 472 views
  • 1 like
  • 3 in conversation