Hi there- I have 4 different terms as Q1, Q2, Q3 Q4, for each subject .
ID TERMS
id1 Q1
id1 Q1
id1 Q2
id1 Q3
id1 Q4
id1 Q4
id2 Q1
id2 Q1
id2 Q2
id3 Q4
I want them like:
Id Terms
id1 Q1 Q2 Q3 Q4
id2 Q1 Q2
id3 Q4
I need a basic array code, here what I drafted does not give the output I need.
data new;
set old;
array T(4) TermsQ1-TermsQ4
Do i=1 to 4;
end;
Any advice? This is a simple array but the out put is not what I wanted.
proc sort
data=have
out=sorted
nodupkey
;
by id terms;
run;
proc transpose
data=sorted
out=want (drop=_name_)
;
by id;
var terms;
run;
Untested, posted from my tablet.
Before you can get an effective response to your question, you'll need to provide more information. In particular
If you provide actual sample data, it will be far easier to help. Your initial data should have for each "row", an ID, a designation of which Q is specified, and the actual value for that ID/Q combination.
What do you want to do with duplicates? Do you want to ignore them?
Where do you want the values to go? If you want them to go into a variable with same name as the value then perhaps just use the LET option on PROC TRANSPOSE will work?
proc transpose data=have out=want let;
by id;
id term;
var term;
run;
Otherwise eliminate the duplicates first.
proc sort nodupkey data=have out=for_transpose;
by id term;
run;
proc transpose data=for_transpose prefix=Q out=want;
by id;
var term;
run;
Here is what the two different outputs look like:
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.