Question

Say if I am creating a dataset with 3 Observations and 2 variables i.e name and id. If out of the 3 observations only 1 observation requires 25 characters .

DATASET practice;
INPUT Name  $25. Id;
DATALINES;
a 20        *1st observation;
abcdefghijklmnopqrstuvwxy 10     *2nd observation;
abc 15;      *3rd observation
run;

Now my question is will sas allocate 25 characters for all the 3 observations or will it act like varchar.

Was it helpful?

Solution

With default options, particularly COMPRESS=NO, SAS will allocate 25 bytes for the character, and pad the unused bytes with spaces ('20'x). That is important not only for storage, but also for character comparisons; while most comparisons ignore trailing spaces, sometimes that's not true and trailing spaces will need to be trimmed explicitly.

However, if you use OPTION COMPRESS=YES or OPTION COMPRESS=CHAR, it will compress the field in datasets that are written out such that it acts more like varchar (it will not take up very much additional space for wasted columns). The spaces are still technically present and may need to be considered in programs, but they do not require a full byte's storage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top