Help using Base SAS procedures

label name display in output

Reply
N/A
Posts: 0

label name display in output

How can I display the entire name of my variables when they are in output. For example in my data step I put
if sex = 'M' then gender = 'male';
if sex = 'F' then gender = 'female';
if sex = 'U' then gender = 'unknown';

when this was outputed it showed up as
gender
fema
male
unkn

How can I get the entire word to show up in the output?
Super Contributor
Posts: 474

Re: label name display in output

Actually, I think the data is correctly displayed...

I suspect you have created the GENDER variable in the input dataset without preassigning to it, the maximum possbible length.
You see, if you do not explicitly define a variable size, SAS will assume one of two things.
If it is a numerical var, it will be defined with the maximum length, being 8 bytes.
If it is a character var, it will be defined with the size of the first value assigned to it during execution.

In your case, I suspect the first value assigned to GENDER was 'male' which is 4 bytes long. From there, all other values where truncated to that size.

For example,

data YOURDATA;
GENDER='male'; output; /* first assignment defines variables size = 4 bytes */
GENDER='female'; output; /* truncated, GENDER='fema' */
GENDER='unknown'; output; /* truncated, GENDER='unkn' */;
run;

to avoid this explicitly define the variable size with the LENGTH statement.

data YOURDATA;
length GENDER $7; /* define GENDER as a 7 byte char variable */
GENDER='male'; output;
GENDER='female'; output;
GENDER='unknown'; output;
run;

Greetings from Portugal.

Daniel Santos at www.cgd.pt
Esteemed Advisor
Posts: 5,156

Re: label name display in output

If you don't want to be concerned about column length, using a user defined format could be an alternative.

/Linus
Data never sleeps
Contributor
Posts: 61

Re: label name display in output

Hello Cg,

See the example.

data test;
input sex$ age;
cards;
m 25
f 60
f 56
m 65
u 52
;
proc format;
value $sexes m = 'male'
f = 'female'
u = 'unknown'
;
proc print;
format sex $sexes.;
run;

or
u can do as per daniel suggestion.
Ask a Question
Discussion stats
  • 3 replies
  • 72 views
  • 0 likes
  • 4 in conversation