Hi,
This is in continuation of an earlier discussion.
I have the following raw data:
Best software for Analytic?
SAS
Microsoft Excel
SPSS
R
Capital of Malvi?
London
Lilongewe
Paris
Which are questions and multiple answers for each question.
I would like to generate the following dataset.
Question | A | B | C | D |
Best software for Analytics? | SAS | Microsoft Excel | SPSS | R |
Capital of Malvi? | London | Lilongewe | Paris |
Note 1: The empty space after "R" suggest the next entry is a question
Note 2: Questions are strings with space in it
Note 3: Multiple answers may have 2 or 3 or 4 items
Any suggestions will be greatly appreciated.
Jijil Ramakrishnan
Oops.
Should I assume you are reading from and external file?
Oops.
Thanks a lot. It worked.
data q; infile cards length=len; input x $varying200. len; if missing(x) then do;group+1;delete;end; cards; Best software for Analytic? SAS Microsoft Excel SPSS R Capital of Malvi? London Lilongewe Paris ;;;; run; proc transpose data=q out=want(drop=group _name_); by group; var x; run;
Xia Keshan
Thanks, this not only helps but this seems easier to program (but data_null's was faster) also. Thanks a lot... Jijil Ramakrishnan
Note 2 is incorrect with your data example. Microsoft Excel has a space but is not a question. I would suspect that a question mark would be a better indicator of a question but depending on how the data was entered I wouldn't bet on it.
Both Null's and KSharp's code took "Microsoft Excel" as a single observation, and generated the output as I hoped it would. I thank you too for the thought.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.