0
votes

I have a numeric variable in a SAS dataset which is length 8. Despite of its length being 8 bytes it contains only one number. See the example bellow.

my_variable
1
2
5
9
0
3

The problem is that I need this variable to be only 1 byte in length and SAS doesn't accept it. I am running the following code:

data my_data_2;
set  my_data;
length my_variable 1;
run;

And SAS reports this error message:

ERROR 352-185: The length of numeric variables is 3-8.

1 - So, why I cannot have a numeric variable with a length less than 3 (or greater than 8) bytes?

2 - Is there a way to manage this? I really need this variable to be length 1.

Edit - adding more context:

I need this specific variable to be length one because I need to submit this dataset to a regulatory authority in my country. They demand this variable to be numeric and length one, otherwise their validation program will not be able to read it. Also, it is needed to be submitted as .DBF file (which is simply done by using SAS proc export statement).

I tried to use Microsoft Access 2013 to change length to 1 and it works. The problem is that Access 2013 does not read or save .DBF as it is an old file format. So, I wanted to change the length in SAS and simply export it .DBF.

3
1) Because they designed it that way. 2) If you could give us some context which explains why you need the variable length to be one, we might be able to come up with some sort of workaround. - Andrew Morton
You confusing length with format length you can format the value F1. But SAS stores numeric variables using 8 byte floating point. Don't change the length of numeric variables it will only cause trouble for you. - data _null_
@AndrewMorton I just edited my question and added more context - Rods2292
Look at DBSASTYPE to see if it allows you to format the character as you create your DBF file. DBF files were supported in Microsoft up until 2010 version but it's still pretty common in some applications - ArcGIS is a common usage. - Reeza
"numeric and length one". SAS doesn't have a numeric type, just character and float. .dbf floating point numbers are not the same as the .dbf numeric type. - david25272

3 Answers

1
votes

According to the documentation:

The minimum length for a SAS variable on Windows and UNIX operating systems is 3 bytes, and the maximum length is 8 bytes. On IBM mainframes, the minimum length for a SAS variable is 2 bytes, and the maximum length is 8 bytes.

The SAS numeric variable length is counted in bytes, not digits.

If you need a flag use character variable instead.

0
votes

The length of a numeric variable in SAS is the number of bytes that it can be stored in. As SAS only uses floating point numerics, they cannot be smaller than 3 bytes in Windows or Unix (2 in z/OS); there is no integer or binary/bit data type in base SAS.

You're welcome to use a format which controls the field width displayed on the screen.

0
votes

I think that PROC EXPORT will write numeric variable with length of 1. You just need to a attach a format to it so that the proc knows that is what you want.

Try this test program.

%let fname=%sysfunc(pathname(work))/test.dbf ;
data test;
 length male 8 sex $1 female 8;
 set sashelp.class(obs=3 keep=sex );
 male=(sex='M');
 female=(sex='F');
 format male female F1.;
run;
proc export data=test outfile="&fname" replace 
  dbms=dbf
;
run;

Then dump the contents of your DBF file as binary to the log

data _null_;
  infile "&fname" recfm=f lrecl=32;
  input;
  list;
run;

and compare it to the description of the file format https://en.wikipedia.org/wiki/.dbf#File_architecture_overview