Date: Thu, 6 Oct 2005 18:24:04 -0700
Reply-To: Daniel Nordlund <res90sx5@VERIZON.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Daniel Nordlund <res90sx5@VERIZON.NET>
Subject: Re: file input question - one last try
In-Reply-To: <AC8B27AA4545474BB8F063FDFE5F2C55191448@GISDSERV03.geneseeisd.local>
Content-type: text/plain; charset=utf-8
David,
I am assuming that the file is structured exactly as you have described it here. Try something like the following. You can adjust variable types, lengths, and formatting of output to taste. The keys are identifying when a new class begins, retaining class specific variables, and ignoring/dropping noise data (blank lines and ----- separators).
Hope this is helpful,
Dan
Daniel Nordlund
Bothell, WA
data students_classes;
infile "your_file.txt" ;
length tag $6 course $10 teacher $10 type $7;
retain type course teacher;
input tag 1-6 @;
select(tag);
when('course') do;
type='course';
input // course teacher // ;
end;
when('------','') do;
type='';
input ;
end;
otherwise type = 'student';
end;
if type EQ 'student' then do;
input @1 name $ id $ grade $;
output;
end;
drop tag type;
run;
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Treder,
> David
> Sent: Thursday, October 06, 2005 4:20 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: FW: file input question - one last try
>
> ________________________________
>
> From: Treder, David
> Sent: Thu 10/6/2005 7:17 PM
> To: David Fickbohm
> Subject: RE: file input question
>
>
> sorry (again), i guess i didn't ask the question properly - let me try one more time.
>
> the file is a plain text file - fixed field, not tab delimited - with a specific structure (in
> looking at your returned e-mail, it appears that the line structure wasn't maintained);
> i'll shorten it, the logic should remain the same:
>
> course teacher
> ---------------
> 501 Smith
>
> name id grade
> --------------------
> Jones 122 B
> Wilson 121 C
> Able 131 D
>
> course teacher
> --------------------
> 202 Dunn
>
> name id grade
> --------------------
> Gunn 341 D
> Frist 130 A
>
> course teacher
> --------------------
> 193 Snoot
>
> name id grade
> --------------------
> Howser 210 B
> James 610 B
>
>
> I would like my sas file to look like:
>
> course teacher name id grade
> 501 Smith Jones 122 B
> 501 Smith Wilson 121 C
> 501 Smith Able 131 D
>
> 202 Dunn Gunn 341 D
> 202 Dunn Frist 130 A
> 193 Snoot Howser 210 B
> 193 Snoot James 610 B
>
>
>
>
> ________________________________
>
> From: David Fickbohm [mailto:davefickbohm@yahoo.com]
> Sent: Thu 10/6/2005 5:28 PM
> To: Treder, David
> Subject: Re: file input question
>
>
> David,
> In that situation you can use proc import.
> Proc import datafile = 'path and filename'
> out = dataset_name
> dbms = tab replace;
> run;
>
> Hope this helps
> Dave
>
>
>
> "Treder, David" <dtreder@GENESEEISD.ORG> wrote:
>
> sorry, it's a text file, and I'm on Windows 2000
>
>
>
> thanks
>
>
>
> ________________________________
>
> From: David Fickbohm [mailto:davefickbohm@yahoo.com]
> Sent: Thursday, October 06, 2005 4:46 PM
> To: Treder, David
> Subject: Re: file input question
>
>
>
> David,
>
> It would help if we knew whether what format this data is in -- excel,
> txt, etc.
>
> It would help if we knew what operating system you are on -- xp, unix,
> etc.
>
> Give us some information and maybe we can help
>
> Dave
>
> "Treder, David" wrote:
>
> I have a file with multiple classes/teachers, with their
> students and
> their grades, set up thusly:
>
>
>
>
>
> Course Description Teacher SEMESTER
> Days Period Room
>
> --------- -------------------------------------- ----------
> ---------- ---------- ------
>
> 4092-07 BIOLOGY S2 APPLEBEE S 2
> MTWRF 02 306
>
>
>
>
>
> Name ID Grd SEM_gr
>
> -------------------------- -------- ----- ----
>
> SMITH, JOHN 007481 10 A
>
> JONES, SALLY 003901 10 B-
>
> .
>
> .
>
> .
>
> (after all the students are listed for this class, the identical
> Course
> header is repeated with a new teacher, etc.)
>
>
>
> I'd like to have a file with a single row for each student (with
> grade,
> id, grade, and em_gr), and with their course and teacher. I've
> scoured
> the archives, but was unable to find an example close enough to
> use.
> Any suggestions?
>
>
>
> Thanks,
>
> Dave
>
>
>
>
>
> *** Scanned by GenNET AV Gateway Out ***
|