DATA Step, Macro, Functions and more

transposing data

Reply
N/A
Posts: 0

transposing data

Hi,
I have a data in this format:
Id Question text
1 c1 xx
1 c3 aa
1 h9 bb
1 h20 cc

I would like to get output in this format

id questInd textInd questocc textocc
1 c1 xx c3 aa
1 h9 bb h20 cc


I want to pair C1 with C3 and H9 with H20. But I don't want to hardcode anything, because the quest pair can change. (It could be c4 and C5 or b11 and b14) etc.
Is there a way I can accomplish this. I tried using first. last. and macro variables and array, but I am not able to get correct output.

thank you.
N/A
Posts: 0

Re: transposing data

Posted in reply to deleted_user
For you to automate the reformating/reconfiguring of any set of data, there has to be recognizable controlling pattern.

So, in your case, what is the pattern?
Is it that the first (odd) observations are "ind" and the second (even) observations are "occ"?

If so, then there are two ways to deal with the situation:
1) random access of the dataset through dataset options.
2) use of the Lag() function.
N/A
Posts: 0

Re: transposing data

Posted in reply to deleted_user
thanks Chuck. You were right in that I had to come up with some pattern to identify the pairs. I accoplished this through the macro variables and the do loop.
Ask a Question
Discussion stats
  • 2 replies
  • 139 views
  • 0 likes
  • 1 in conversation