LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (November 2011, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 6 Nov 2011 18:50:13 -0600
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: Help in destringing mult vars then recoding into new
              indicator vars
Comments: To: Alison <alisontetler@yahoo.com>
In-Reply-To:  <201111070024.pA6BpDMa021197@waikiki.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1

The general pattern will be something like data want; set have; array xvar[15]; do _x = 1 to dim(xvar); if find(x,byte(64+_x)) then xvar[_x] = 1; else if not missing(x) then xvar[_x] = 0; end; run;

Now that assumes a few things - one, that you have values A-O in your data, and two, that you want to set them to 0 only if there is some value in the variable. I'm using 'x' as the variable, xvar_# as the spread variables. If you have more than 1 variable, you can create a macro to repeatedly do this.

Byte(64+_x) is creating the A-O values (byte = character representing the number ni the (), and A is 65 -> Z is 90, capital only [96+_x would be a-z].

You might consider a different data structure, though, depending on what you're doing with your data. Particularly if you have a lot of different variables per respondent like this, the data will be a mess. A structure where instead of 1 row per respondent, but 1 row per condition [with 15 different slots for the various options] might be better. That would be similar:

data want; set have; array conditions[15]; array types[8] a b c d e f g h i j; do _type = 1 to dim(types); type = vname(types[_type]); do _cond = 1 to dim(conditions); if find(types[_type],byte(64+_cond)) then conditions[_cond] = 1; else if not missing(types[_type]) then conditions[_cond] = 0; end; output; end; keep conditions1-conditions15 type respondent_id; run;

This is a bit simpler really; but the core loop is the same, inside a one-per-type loop. Change the array list for types to whatever the actual variables are for the various types. Then you can do your analyses using BY TYPE; if you need analyses per type.

If these aren't what you're looking for, reply to the list with some more information [more detailed sample data, and what you want it to look like and/or what analyses you're doing).

-Joe On Sun, Nov 6, 2011 at 6:24 PM, Alison <alisontetler@yahoo.com> wrote: > Hi, I have about 30 variables with responses of varying length, all > character. For example, one person's value may be A while another's could > be AFEG - up to 8 characters long. They are basically compilations of a > number of conditions that a person reported, so can be any combination of > about 15 different options. I am looking to write a program that will take > each of these main variables, create the 15 new variables that will indicate > presence/absence of that symptom, have SAS scan through to see if that > particular character is within the response, and output the 1 or 0. At this > point I am destringing each variable and then recoding, but it is taking me > a long time and there is most certainly a more efficient and succinct way to > do this. Can anyone help? > > Thank you all so much, > Alison >


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