@chopra wrote:
@ballardwThank you for your reply.
I think you are right. My data set looks something like this. Where i have 32 character variables, who have values A,Z,E,D and so on. They are joined using the ID no. of each individual. The values do consist of a single character
The code that you provided above gives me the number of Sequence Id who have A or Z. How do I put in the code for the number who dont have it.
On generic approach is IF/then/ Else.
If <condition> then caries=1;
Else if <another condition> then caries=1;
else if <different condition> then caries=1;
else caries = 0;
If you have a whole lot of these that you are searching for specific values then an array may be what you want as there is a function WHICHC (or WHICHN when looking for numeric values) which returns which variable matches (equals) the value or 0 if not found. I didn't recommend this first as I was not sure you might not have been looking for an "F" that occurred in "FX" in a single variable for instance.
data example;
input a $ b $ c $;
array z a b c;
Fpos = whichc('F',of z(*));
datalines;
F F F
X X X
Z E D
;
run;
So you could also use
If whichc('F', of array(*))>0 then caries=1; which would then tie back to the If/then/else and have somewhat easier on the eyes code.
The "of array(*)" construct is available for many functions that take multiple parameters and places all of the current values of the array into the function. Cats( of array(*)) for instance will work.
So adding a statement such as
array ohx OHX31CTC OHX30CTC OHX29CTC OHX28CTC OHX27CTC OHX26CTC OHX25CTC OHX24CTC OHX23CTC
OHX22CTC OHX21CTC OHX20CTC OHX19CTC OHX18CTC OHX15CTC OHX14CTC OHX13CTC OHX12CTC
OHX11CTC OHX10CTC OHX09CTC OHX08CTC OHX07CTC OHX06CTC OHX05CTC OHX04CTC OHX03CTC OHX02CTC ;
and use of the array named ohx may help.
Since WHICHC returns a numeric position you might consider the order of the variables if you need a search done in a specific order as WHICHC returns the position of the first found match.
Note that many long term SAS programmers would have created variables names as OHXCTC31 etc as then the array array statement (or other shorthand lists) could use OHXCTC02 - OHXCTC31 or even just OHXCTC: (note the colon );
BTW I kind of would expect an OHX01CTC and OHX32CTC since caries implies something with dental processes to me and generally 32 teeth.
... View more