I have the following SAS table:
City grade1 grade2 grade3
NY A. A. A
CA. B. A. C
I would like to merge the three last variables into a single one; this is the expect output:
City grade
NY A.
NY. A.
NY. A.
CA. B.
CA. A.
CA. C.
I tried with Proc transpose but it seems not the right way. What am I supposed to do?
Sort the data by the City variable so you can use it as a BY and then use PROC TRANSPOSE.
data have;
input City $ grade1 $ grade2 $ grade3 $;
cards;
NY A. A. A
CA. B. A. C
;;;;
proc sort data=have; by City;run;
proc transpose data=have out=want prefix=Grade;
by City;
var grade1-grade3;
run;
proc print data=want;run;
Results:
Obs City _NAME_ GRADE1
1 CA. grade1 B.
2 CA. grade2 A.
3 CA. grade3 C
4 NY grade1 A.
5 NY grade2 A.
6 NY grade3 A
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.