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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 1806 views
  • 2 likes
  • 2 in conversation