BookmarkSubscribeRSS Feed
Bulleride
Obsidian | Level 7

QUESTION 64
The following SAS DATA step is submitted:
data work.accountting;
set work.department;
length jobcode$ 12;
run;
The WORK.DEPARTMENT SAS data set contains a character variable named
JOBCODE with a length of 5.
Which one of the following is the length of the variable JOBCODE in the output
data set?

A. 5
B. 8
C. 12
D. The length can not be determined as the program fails to execute due to errors.

 

 

Ans –A  (WHY? Why not 12?)

3 REPLIES 3
mohamed_zaki
Barite | Level 11

Because the variable length is already defined by the set statment as in the original data set.

When it will be 12? if the length statment come before the set statament. So order is very important here.

And if you have practicing SAS programming  you will know that if you run this programe you will get a warning.

 WARNING: Length of character variable jobcode has already been set. 
          Use the LENGTH statement as the very first statement in the DATA STEP to declare the length of a character variable.

And not 8 for two reasons the one mentioned above plus this length is not defined any where in the data step or the original data and it is char not number. where if it is number the max length is 8.

Bulleride
Obsidian | Level 7
But won't this length statement overwrite the length that the original data set contained and make it 12?
mohamed_zaki
Barite | Level 11

No, not in SAS. Only if it come before the set statment in the order in your data step.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2123 views
  • 2 likes
  • 2 in conversation