BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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?
3 REPLIES 3
DanielSantos
Barite | Level 11
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
LinusH
Tourmaline | Level 20
If you don't want to be concerned about column length, using a user defined format could be an alternative.

/Linus
Data never sleeps
venkatesh
Calcite | Level 5
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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1452 views
  • 0 likes
  • 4 in conversation