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.
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;
did I misunderstand the instructor or did I do something wrong in the code?
You are changing the length of NAME in the dataset CLASS_CURRENT not SASHELP.CLASS.
You are changing the length of NAME in the dataset CLASS_CURRENT not SASHELP.CLASS.
thanks man.
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?
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.
@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?
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.