Print

Print


Hello,
I would like to thank Dr.Martyn Byng ,Dr.John D. McClure,Dr.Miland Joshi and Dr.Kathleen McCaffrey and Dr.Roberto for their repies as below.

I can read and separate two file :head and student file.
I have some quesion as below.
I know  head1-head6 variables of student file in each course have an error and the correct one is head1-head6 variables of head file so I would like to copy all variables of head file in each course to head1-head6 of variables of student file in that co
rse.

I tried to write as you advised as below but it has a problem in this part.I spent a lot of time for this,but it did not work.
 
e.g SAS program is as below

option pagesize=60 linesize=80;
data head (keep=head1-head6 ) 
   student (keep=head1-head6   q1-q8);
array head[6] ;
array temp{6} ;
array q[8] ;
retain head;
infile cards missover;
input head1 1 head2 2-4 head3 5-6 head4 7 head5 8 
      head6 9  q1 10 q2 11 q3 12 q4 13 q5 14 q6 15 q7 16 q8 17;

if (head1 = "") then 
  output student;
else do;
  do cc = 1 to 6;
     end;
  output head;
end;
cards;
101104021        
  1   02153454455
 0110402134455554
 0110402134545545
  1     145555555
 0110422135343333
 0110402142142333
 0111102124555555
101101021        
 0112 02124555455
  1 2 02133363343
 0110202123555555
 0112 02 3324434 
  111102144554344
 0110202134455445
 0110202 34455345
 0110202144333333
 0110202124555555
 0110202 34263323
  1 2 02 23344434
 011  02133243434
 0112 02 34464444
 0110202134363333
 0112 02122245544
 0110202134545445
 0112 02 22455445
 0112 02135554424
101105021        
 0110502123464354
 0115 02144343343
 0115 02123465555
 0115 02123555535
 0115  2123555535
;
run;
title "Head Data";
proc print data=head;run;
title "Student Data";
proc print data=student;
run;
data together;
merge head (rename=(head1=h1 head2=h2 head3=h3 head4=h4 head5=h5 head6=h6 ))
student;
by head;
run;
proc print data=student;
run;



Can anyone know how to use SAS command for these ?
I would also appreciate some comments about these.
Sorry for long message.
 
 Have a nice day!
 Cheers,
 Nantana Naranong
 
 
-------------------------------------------
-----Original Message-----
From: nantana naranong [[log in to unmask]]
Sent: 09 October 2000 00:31
To: [log in to unmask]
Cc: [log in to unmask]
Subject: SAS programming

> Hello,
> I have many data of teaching evaluation approximately 7-8 years. 
> The detail is as below.
> 
> There are head data and student data in each course.
> The first line is head data and the second line to end are student data in each course.
> These must have column 1-9 the same,but there are some error on student data in these column.
> 
> I would like to 
> i)read head line and copy all variables to same variables in student lines in each course. And then
> ii)skip head line and read student lines all variables in column 1-17.
> 
> Variables in head data are head course section year semester deparment  and
> variables in student data are head course section year semester deparment question1-8.
> 
> e.g. data is as below.
> 
> 101104021          head data in course 101
> *1  02153454455      student data
> *0110402134455554      ....
> *0110402134545545      ....
> * 1   145555555      ....
> *0110422135343333      .....
> *0110402142142333      .....
> *0111102124555555      student data
> 101101021          head data in course 102
> *0112 02124555455      student data 
> * 1 2 02133363343      ....
> *0110202123555555      ....
> *0112 02 3324434 
> * 111102144554344
> *0110202134455445
> *0110202 34455345
> 
> I spent a lot of time for this,but it did not work.
> Can anyone know how to use SAS command for these ?
> I would also appreciate some comments about these.
> 
> Have a nice day!
> Cheers,
> Nantana Naranong
> 
> 
> 
---------------------------------------
Date Mon, 9 Oct 2000 14:23:45  0100 (BST)
To nantana naranong <[log in to unmask]>
Author Martyn Byng <[log in to unmask]>
Subject Re: SAS programming

The following section of code should give you something easily to alter.
It makes the following assumptions:

(1) The data is currently being read in from the cards statement. To
change this to an input file remove everything beow (and including) the
line `cards;' and change the infile statement to read
infile file="your filename in here" missover;

(2) All the information is character (you will need to change the array
types if not, by removing `$ 100' if the data is numeric).

(3) The way to distinguish between a students record and the head record
is when the first question is missing (i.e. the sixth record in the
dataset is missing for the head record and present in the student record).


Hope this helps

data head (keep=head1-head5) 
   student (keep=head1-head5 q1-q8);
array head[5] $ 100;
array temp[5] $ 100;
array q[8] $ 100;
retain head;
infile cards missover;
input temp1-temp5 q1-q8;
if (q1 ne "") then 
  output student;
else do;
  do cc = 1 to 5;
   head[cc] = temp[cc];
  end;
  output head;
end;
cards;
a b c d e
a d d d d 1 2 3 4 5 6 7 8
a a a a a 1 2 3 4 5 6 7 8
;
run;
title "Head Data";
proc print data=head;run;

title "Student Data";
proc print data=student;run;



--------------------------------------------------------
Date Mon, 9 Oct 2000 12:36:06  0100 (BST)
To [log in to unmask]
Author johndm <[log in to unmask]>
Subject Re: SAS programming

Hi,

Queries regarding specific software packages are better sent to
the appropriate software mailing list rather than Allstat.

For example, you might try the sas-l list, details of which can
be found on the Allstat webpage
   http://www.stats.gla.ac.uk/allstat/
under the "Other Statistics Lists" link.

Cheers, 

John

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

John D. McClure

Department of Statistics         Phone :  44 (0)141 330 6118
University of Glasgow          Fax  :  44 (0)141 330 4814
       
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[log in to unmask]  http://www.stats.gla.ac.uk/allstat
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-------------------------------------------------------------------
Date Mon, 9 Oct 2000 08:47:26  0100
To "[log in to unmask]" <[log in to unmask]>
Author "Joshi, M." <[log in to unmask]>
Subject RE: SAS programming

Hi Nantana

You might be able to carry out your task using row pointers, dealt with on
page 285 of Cody and Smith's Applied Statistics and the SAS Programming
Language (4th ed 1997, ISBN 0137436424). Note that you need the same number
of rows per subject.

So here's one posible answer:

data students;
  input  #1 head 1-3 course 4 section 5 year 6-7 semester 8
department 9
   #2 head 1-3 course 4 section 5 year 6-7 semester 8
department 9 question1_8 10-17;
datalines; 
.
.
.

etc

[or, use infile statement before input as follows:

data students;
  infile 'a:students.dta';
  input  #1 head 1-3 course 4 section 5 year 6-7 semester 8
department 9
   #2 head 1-3 course 4 section 5 year 6-7 semester 8
department 9 question1_8 10-17;
]


The above is only an example, as you have not said exactly how the columns
are split up. 
Also, I am not sure how you would deal with missing data unless you cleaned
the data set first. One possibility might be to import the data into another
package and clean it before trying the SAS programme. If you did this in
SPSS or S-Plus you might not need SAS in that case! Anyway, good luck.

Regards
Miland Joshi (Mr.)

Department of Epidemiology and Public Health
University of Leicester 


-------------------------------------------------------------
Date Mon, 9 Oct 2000 08:33:58  0100
To <[log in to unmask]>
Author "Kathleen McCaffrey" <[log in to unmask]>
Subject RE: SAS programming

Does one column contain the course number (I can't work that out from the
data you have shown)?
If so, you can use

data heads students;
 set dataset;
 by courseno;
 if first.courseno then output out=heads;
 else if not first.courseno then output students;
run;

You may have already tried that .. but just a suggestion.

Good luck

Kathleen


------------------------------------------------------------
Date Mon, 9 Oct 2000 09:12:00  0100
To [log in to unmask]
Author [log in to unmask]
Subject SAS programming

Try doing it in steps: first, read all data regardless they are head or
student, identifying each variable by specifying the position in the
string, then run a data step putting head data in one file and student data
in another creating a key variable for a merge. Finally, merge them
together on the key variable, renaming variables coming from head.

The following SAS program seems to work on the data you sent by e-mail.

Good luck
Roberto


/* read data */

data prova;
input v1 $1 v2 2 v3 3 v4 4 v5 5 v6 6 v7 7 v8 8 v9 9 v10 10 v11 11
   v12 12 v13 13 v14 14 v15 15 v16 16 v17 17;
cards;
101104021
*1  02153454455
*0110402134455554
*0110402134545545
* 1   145555555
*0110422135343333
*0110402142142333
*0111102124555555
101101021
*0112 02124555455
* 1 2 02133363343
*0110202123555555
*0112 02 3324434
* 111102144554344
*0110202134455445
*0110202 34455345
;
run;


/* separate files */

data head(keep=head v1ok v2-v9)
   student(keep=head v2-v17);
set prova;

if v1 ne '*' then do;
 head   1;   * head identifies each new head/student block - key variable for merging;
 v1ok = v1 * 1; * putting alpha variable v1 as numeric;
 output head;
end;

if v1 = '*' then output student;
run;


/* putting all together again */
/* variables from head lines are named h1-h9 */

data toghethe;
merge head(rename=(v1ok=h1 v2=h2 v3=h3 v4=h4 v5=h5 v6=h6 v7=h7 v8=h8 v9=h9))
   student;
by head;
run;

----------------------------------------
 








%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%