Date: Wed, 3 Dec 2008 22:16:33 -0500
Reply-To: "A.B." <alicia.bingo@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "A.B." <alicia.bingo@GMAIL.COM>
Subject: Re: Convert and store format value into a character variable
Content-Type: text/plain; charset=ISO-8859-1
I was trying to get a bunch of crosstabs using a SAS macro . The format for
each of the variables were messed up when I put the result tables (from ODS
output) together. I think it is because the formats are all numeric and SAS
just uses the format for the first variable.
Your and Randy's solution: The newCharVar=put(gender, sex.);
gender_formatted = put(gender,sexfmt.); is what I was looking for. I just
need to get the format from the format library for each variable. I think
that's what was suggested in the sas comm wiki page Ronald mentioned. I will
try that at work tomorrow.
Thank you all for your help!
On Wed, Dec 3, 2008 at 5:30 PM, Nordlund, Dan (DSHS/RDA) <
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
> > Behalf Of A.B.
> > Sent: Wednesday, December 03, 2008 1:59 PM
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: Convert and store format value into a character variable
> > Hi,
> > I was wondering if there's a way to convert/store format value into a
> > character variable. An example:
> > Gender is a numeric variable and has tow values with the
> > following format:
> > 1=Male 2=Female
> > I want to use the format value (not the value of the
> > variable) in some way.
> > How can I achieve that?
> > Thanks!
> > --
> > A.B.
> Here is one way:
> Proc format:
> value sexfmt
> 1 = 'Male'
> 2 = 'Female'
> Data want;
> set have;
> length gender_formatted $6;
> gender_formatted = put(gender,sexfmt.);
> Having said that, you can probably achieve what you want without creating
> an additional variable. So, exactly what are you trying to do?
> Daniel J. Nordlund
> Washington State Department of Social and Health Services
> Planning, Performance, and Accountability
> Research and Data Analysis Division
> Olympia, WA 98504-5204