05-08-2012 11:28 AM
I am working with an interesting data set, however I am having difficulty cleaning it up due to certain imported formatting issues I am encountering.
The data set is expanded with multiple columns indicating response to surveys. I am trying to condense the data set columns in SAS to have responses to each question unique to each column.I am a little confused on where to start for the coding. For instance:
Data set now:
Respondent ID K 1 2 3 4
I would like to have
Respondent ID Grade
I have attached the sample Excel document with the dataset for further details.
Thanks in advance!
05-08-2012 11:54 AM
You could just use the coalesce function. E.g.:
input id k _1 _2 _3;
1 . . 3 .
2 1 . . .
3 . . . 4
data want (keep=id grade);
05-08-2012 12:00 PM
Another possibility: read in the data yourself, in a DATA step, rather than importing it from Excel. When you do that, omit the DSD option from the INFILE statement, so that multiple consecutive delimiters get treated as a single delimiter. In that case, you could simply use:
input respondent_ID $ grade;
05-08-2012 10:31 PM
I like Art's code. Why do you have to use proc transpose ?
data have; input id k _1 _2 _3; cards; 1 . . 3 . 2 1 . . . 3 . . . 4 ; run; proc transpose data=have out=want(drop=_name_ where=(col1 is not missing)) ; by id; var k _1 _2 _3; run;
05-09-2012 11:33 AM
I'd say go back to SurveyMonkey (or other survey program, example sure looks like SurveyMonkey to me) and look at your data export options. There is one that provides one response per question instead of this format.