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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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