Date: Tue, 22 May 2007 16:54:13 -0700
Reply-To: "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Subject: Re: Autorecode strings to numeric
In-Reply-To: <7b53245b0705221634g4464be51r1cf9703b94abde53@mail.gmail.com>
Content-Type: text/plain; charset=iso-8859-1
> -----Original Message-----
> From: Jeremy Miles [mailto:jeremy.miles@gmail.com]
> Sent: Tuesday, May 22, 2007 4:34 PM
> To: Nordlund, Dan (DSHS/RDA)
> Cc: SAS-L@listserv.uga.edu
> Subject: Re: Autorecode strings to numeric
>
> On 22/05/07, Nordlund, Dan (DSHS/RDA) <NordlDJ@dshs.wa.gov> wrote:
>
> [snip]
>
> >
> > I guess I misunderstood what you wanted to do. It would
> definitely help to see a sample of the data that you want to
> convert. However, from your log it looks like string takes
> on values like
> >
> > Active PH Client
> > Administrative Discharge
> >
>
> That's right, there are quite a few of these, and some of
> them are quite long.
>
> > So, is your task to give these string values an abitrary
> numeric code? This could be
> >done using a format or a variety of other techniques. For example,
> something like
> >
>
> Yes. I'm new to SAS, having used SPSS before. The autorecode command
> (in SPSS) puts the values into alphabetical order, and creates a new
> variable, where the first becomes 1, the second becomes 2, etc.
>
> > Proc format;
> > value $strfmt
> > 'Active PH Client' = 1
> > 'Administrative Discharge' = 2
> > other = 3
> > ;
> > Run;
> > data temp1; set temp2;
> > num = input(put(string, $strfmt.), best.);
> > run;
> >
> >
> > Write back to SAS-L with details of what your string looks
> like and what your recoded
> > values should be, and maybe the higher goal that you are
> trying to achieve. That way
> > someone may be able to give you better advice.
> >
>
> I wanted to write some code to place these into groups, so 1, 2, 3, 6,
> 7 and 9 (for e.g.) would become 1, and 8, 13, 14, etc, would become 2.
>
> I could then write
> if code = 1 or code = 2 or ... then censored = 1;
>
> Without having to write each string out in full (and risk
> making mistakes).
>
> Jeremy
>
>
> > Hope this is helpful,
> >
>
> Yes, thanks,
>
> Jeremy
>
This is helpful information. What you want to do can be done by building a format, or a lookup table, or .... I will have to think about what might be most useful. I also suspect that there are others on the list who will be able to provide a (better) solution based on this description. As it is late in the day for me, and I have an 2-hour commute ahead of me, I probably won't get back to this till tommorrow.
Dan
Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services
Olympia, WA 98504-5204
|