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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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