BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
loedrup_ab
Calcite | Level 5

Dear anyone

Given the single choice answer in q1 (a-d) repondents get to answer q2a - q2d,(single choice, a - e) as shown in excel below. How can I summarize q2a - q2d in q3  as shown in excel below?

Hope to hear from you

sincerely Anders

q1q2aq2bq2cq2dq3
aee
abb
caa
bdd
dcc
1 ACCEPTED SOLUTION

Accepted Solutions
shivas
Pyrite | Level 9

Hi,

Is this what you are looking for? or i have not understand your requirement.

data have;

infile cards dsd dlm=',';

input q1 $ q2a $ q2b $ q2c $ q2d $;

q3=COALESCEC(q2a,q2b,q2c,q2d);

cards;

a,e,,,

a,b,,,

c,,,a,

b,,d,,

d,,,,c

;

run;

Thanks,

Shiva

View solution in original post

2 REPLIES 2
shivas
Pyrite | Level 9

Hi,

Is this what you are looking for? or i have not understand your requirement.

data have;

infile cards dsd dlm=',';

input q1 $ q2a $ q2b $ q2c $ q2d $;

q3=COALESCEC(q2a,q2b,q2c,q2d);

cards;

a,e,,,

a,b,,,

c,,,a,

b,,d,,

d,,,,c

;

run;

Thanks,

Shiva

loedrup_ab
Calcite | Level 5

Hi Shiva

Super. The COALESCEC(q2a,q2b,q2c,q2d) did the trick

I just did (data 'have' contains the values of q1 and q2a - q2d):

data want; set have;

q3=COALESCEC(q2a,q2b,q2c,q2d);

run;

Thank you for helping out.

cheers Anders

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1067 views
  • 4 likes
  • 2 in conversation