SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
2 REPLIES 2
deleted_user
Not applicable
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.
deleted_user
Not applicable
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.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1033 views
  • 0 likes
  • 1 in conversation