0

When I set a character's variable length to 2 bytes, the data set only shows one character. However, when I print it, the full input displays. To make things even weirder, when I change only the variable name, the problem goes away. Below are code samples accompanied by screen shots of my data views and PROC PRINT results.

I am using SAS 9.4 on Windows 7. I'm not sure what encoding is being used. As I've never changed it, I assume my encoding is wlatin1, as per this white paper. This should mean that each ASCII character is 7 bits. So, a length of 2. should be 16 bits, leaving 2 bits remaining when storing "AA".

I'm at a loss to explain what is going on and am concerned that I may be inadvertantly losing data.

data test1;
  length  cut   $ 1.
          full  $ 2.
          ;

  cut   = "AA";
  full  = "AA";
run;

proc print data = test1;
run;

I find that if I change the name of the variable, but keep everything else the same, the input displays properly in the data set as well as the output.

data test2;
  length  one_byte   $ 1.
          two_bytes  $ 2.
          ;

  one_byte   = "AA";
  two_bytes  = "AA";

run;

proc print data = test2;
run;

Below are screen shots of my data views and results window.

data set views results

Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
  • If you tell it the length is only one byte and try to assign more than one byte to it the extra bytes are ignored. Why does this surprise you? Are you just complaining the ViewTable is too stupid to set the width of the column? – Tom Nov 04 '16 at 01:30
  • I fail to see how your comment is intended to be constructive. It appears almost as if you didn't read the question. The statement "I'm ... concerned that I may be inadvertently losing data" clearly states why I posted this. Do you mean to say that you find the question unclear? The answer did indeed turn out to be that the ViewTable auto-adjusts column width based on variable name and not on the data. This is not obvious and took more than an hour to discover. I would like to save someone else this effort. If you think rewording the question might help, I will gladly do so. – Lorem Ipsum Nov 22 '16 at 19:33
  • Re wording might help as it made it sound like SAS has truncated the data, which turned out to not be the case. Instead it turns out that it is a question about the behavior of just one aspect of the GUI based user interface instead. If you define the variable as length two bytes then SAS itself definitely shows you both bytes. It is just the ViewTable application that was causing the confusion. – Tom Nov 22 '16 at 22:32
  • I appreciate your feedback. I'll revise the wording of the question. Thanks! – Lorem Ipsum Nov 23 '16 at 15:02

2 Answers2

1

It appears that the field width in the data view isn't automatically adjusted by the value of the observations. Notice that "full" has a slightly lesser length than "AA" so that the field width cuts off the second "A". Drag the field header over and the 'missing' characters appear.

"full" is shorter than "AA" I hate SAS so much

Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
1

As you point out, the columns in ViewTable do not automatically resize to show entire contents of the variable.

An alternative approach would be to use 'Form View' - available in the toolbar along the top:

form view in sas explorer

This could be assigned to a shortcut key, eg as follows:

dm "keydef F4 'viewtable &syslast view=form'";

Yet another approach (if using a version of base SAS earlier than 9.4) would be to use FS View (credit Jay Stevens) - for example:

dm "fsv sashelp.class";

enter image description here

More info on display manager shortcuts available here.

Community
  • 1
  • 1
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124