Restructuring Data

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Restructuring Data

E. Bernardo
Dear All,
 
I have a dataset with three variables such as ID, Subject, and Grade.  ID is numeric and unique for each person(case). Subject is string while Grade is numeric.  The format of the dataset looks like as follows:
 
ID    Subject  Grade        
1         X          2                 
1         Y         3                  
1         Z          2                  
1         W        2.5                
2         X          4.0               
2         Y         3.0                
2         Z          4.0                
2         W        4.0                 
3          X         4.0                         
3          Y         3.0                
3           Z         3.0                
3          W        3.0                 
 
I want to restructure/reformat the data such that the format looks like as follows:
 
ID         X       Y           Z    W
1          2       3           2     2.5
2          4.0    3.0        4.0   4.0
3         4.0     3.0         3.0   3.0
 
Can someone help me on this?
 
Thank you.
Eins          

Reply | Threaded
Open this post in threaded view
|

Re: Restructuring Data

Ruben Geert van den Berg
Dear Eins,
 
I think the syntax below does the job. If the new variable order is not of your liking, you can use MATCH FILES in order to adjust it.
 
HTH,

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com


preserve.

set decimal dot.
 
data list free/ID (f2)   Subject(a1)  Grade    (f2.1).
begin data   
1         X          2                 
1         Y         3                  
1         Z          2                  
1         W        2.5               
2         X          4.0               
2         Y         3.0                
2         Z          4.0                
2         W        4.0                 
3          X         4.0                         
3          Y         3.0                
3           Z         3.0                
3          W        3.0              
end data.
 
sort cases by id subject./*just in case...
 
casestovars
 /id=id
/index=subject.
 
restore.
 

Date: Thu, 10 Jun 2010 15:02:29 +0800
From: [hidden email]
Subject: Restructuring Data
To: [hidden email]

Dear All,
 
I have a dataset with three variables such as ID, Subject, and Grade.  ID is numeric and unique for each person(case). Subject is string while Grade is numeric.  The format of the dataset looks like as follows:
 
ID    Subject  Grade        
1         X          2                 
1         Y         3                  
1         Z          2                  
1         W        2.5                
2         X          4.0               
2         Y         3.0                
2         Z          4.0                
2         W        4.0                 
3          X         4.0                         
3          Y         3.0                
3           Z         3.0                
3          W        3.0                 
 
I want to restructure/reformat the data such that the format looks like as follows:
 
ID         X       Y           Z    W
1          2       3           2     2.5
2          4.0    3.0        4.0   4.0
3         4.0     3.0         3.0   3.0
 
Can someone help me on this?
 
Thank you.
Eins          



Express yourself instantly with MSN Messenger! MSN Messenger