I have a data file of survey responses where each record is a response to a single question by a single respondent. For each record, the respondent creates a pattern 1's and 0's that is stored in variables p1-p10.
I also have a string variable in the file called key that is the key to scoring the pattern of values in p1-p10 as either correct or incorrect.(e.g, string value in key might be "p7 and ( p3 or p8 )") .
So, now I want to score records in the file by creating a new variable called "iscorrect" that is value 1 if the logical expression in the key field resolves to true, value 0 otherwise.
Example: If the key field is "p7 and ( p3 or p8 )" and the value of variables p7 and p8 are 1, then iscorrect is 1.
I've been having difficulty using the macro facility to evaluate the string "key" variable as a logical expression. Any suggestions?
I don't know of an elegant way to evaluate the expression in KEY as the data step executes. SAS does not have an EXECUTE (data step code) function, AFAIK.
You could code gen some "wall paper" for example. I hope my example data is suitable to model your process.
input (p1-p10)(1.) +1 key $64.;
id + 1;
0010011101 p7 and ( p3 or p8 )
0010010101 p7 and ( p3 or p8 )
0010010101 p4 and ( p5 or p8 )
0010010101 p7 and ( p4 or p10)
0010010101 p6 and ( p3 or p8 )
proc sort data=test(keep=key) out=keys nodupkey;
filename FT79F001 temp;
put +6 'when(' key:$quote66. ') iscorrect = ' key ';';
%inc FT79F001 / source2;
Bless you, data _null_!
Your "test" table is precisely the input and your "iscorrect" table is the correct output. (Now I'll just have to step through your "FT79F001" processing to understand how you did it!)
It's great to end the weekend knowing that it can be done.
Thanks again, robin