BookmarkSubscribeRSS Feed
Jianan_luna
Obsidian | Level 7

I took quiz from SAS programming 1, I think the length is 8. But the answer is 6. Could anyone help me about it?

Jianan_luna_0-1594266594877.png

 

2 REPLIES 2
ketpt42
Quartz | Level 8
The assignment to 'luxury' in the 3rd line sets the length at 6. Put the length statement prior to the assignment to get the correct length.
Kurt_Bremser
Super User

When the data step compiler compiles the code, it sets variable attributes from the first encounter of a variable where the attribute can be deduced.

In your case this is the statement where the 6-character string "luxury" is assigned; subsequent changes in the length are ignored.

Make it a habit to put attribute-setting statements (ATTRIB, LENGTH, FORMAT, but also SET, MERGE, UPDATE) into the top of your data step code.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 843 views
  • 0 likes
  • 3 in conversation