Hi,
I am a new learner of SAS, this maybe a easy stuff for you.
my dataset look like this
ID Q1 Q2 Q3 Q4 Q5
1 NA Y N N Y
2 Y Y N NA NA
3 N N Y Y N
and I want to make the dataset into the following way
ID Q1 Q2 Q3 Q4 Q5 Yes_question
1 NA Y N N Y Q2 Q5
2 Y Y N NA NA Q1 Q2
3 N N Y Y N Q3 Q4
I have tried the following code
data dataset2;
set dataset;
yes_question2=" ";
retain yes_question2;
array yes(5) Q1--Q5;
do i = 1 to 5;
if yes(i)="Y" then yes_question=cat(yes_question2," ",vname(yes(i)));
yes_question2=yes_question;
end;
run;
But yes_question2 keeps equal to blanks and I can only get the result of blank+last Yes question.
Any simple code to make this possible?
Thanks for the help.
data watn;
set have;
array var Q:;
length yes $10;
do over var;
if var='Y' then Yes=catx(' ',yes,vname(var));
end;
run;
CAT() function does not trim so you are essentially reassigning the empty value in YES_QUESTION to itself.
yes_question=catX(' ',yes_question,vname(yes(i)));
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.
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.