LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 21 Nov 2005 13:36:04 -0500
Reply-To:     Mike Rhoads <RHOADSM1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mike Rhoads <RHOADSM1@WESTAT.COM>
Subject:      Re: How to add decoded variables.
Content-Type: text/plain; charset="us-ascii"

Assuming you do need to do this -- one reason would be if you want to export your SAS data to some other package and keep both the "raw" and formatted values -- this is a challenging, but doable, assignment.

Ian's template should help you get started.

If you are using SAS 9, take a look at the SASHELP.VFORMAT view. This provides information about all formats, and should enable you to distinguish between builtin and user-defined formats, since you state that you only want the extra variable for the latter. (There are many builtin formats, of course.)

You'll also need to get the variables into your desired order, and to get the correct length for each of the new __d variables.

If I am understanding your specification correctly, you want to generate code like the final DATA step below.

PROC FORMAT; VALUE $SexFmt 'F' = 'Female' 'M' = 'Male' Other = '???' ; RUN;

DATA ClassCopy; SET SASHELP.Class; FORMAT Sex $SexFmt.; RUN;

DATA NewClass; /* RETAIN used to get the desired order */ RETAIN Name Sex Sex__D Age Height Weight; LENGTH Sex__D $ 6; SET ClassCopy; Sex__D = PUTC(Sex,VFORMAT(Sex)); RUN;

Mike Rhoads Westat RhoadsM1@Westat.com

-----Original Message----- From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of SAS_my_life Sent: Monday, November 21, 2005 11:21 AM To: sas-l@uga.edu Subject: How to add decoded variables.

Hello guys I need to something like this can you help me how exactly to do it,

Add one variable for every variable in the source dataset which has a user-defined format. The new variable will contain the decoded value and be located next to the original variable, with __d appended to the variable name. The log will inform the user if the format was not found or if the particular value was not found for the given format.

proc sort data=dslist out=fixcode; by memname name; * where format not in (' ', '$'); run; data test; set fixcode end = eof; call symput('newname'||compress(put(_n_, 4.)), compress(name||'__d')); run;

I started doing some thing like this but this is not working , I appriciate any kind of help.

thanks phani


Back to: Top of message | Previous page | Main SAS-L page