Prev: Finding the variables with all missing values
Next: Proc logistic: how to add constraints on variables?
From: Steve on 21 May 2010 22:53 I have a long text file where each line represents one of 10 different text or date variables. Each variable line starts with its own identifier (like Recnum: or Start_Date:). The variable RECNUM indicates the start of a new 10-line record; the variable Final is the last one in the record. At each encounter of RECNUM I want to loop through the variables until I hit another RECNUM, and then output the 10 variables into one record, then do it again for all 600 records in the text. Unfortunately, it's been 15 years since I've done any serious SAS programming, though I have v. 9.2 handy (but no SAS docs around). Can someone point me to a sample program that does the following: -- Steps through a text file with multiple lines for each record, with each line representing one variable; -- Uses IF-THEN-ELSE statements to read the start of each line to detect which variable is being read and saved; -- Outputs the record into a SAS dataset once the last line in a record has been read; -- Then clears all the variables and does the above over again at the beginning of the next record in the text, until all records are read. I know it's pretty simple because I've written programs like this in the distant past. But I don't remember the details of the necessary @s and RETAINs and such. So thanks for any guidance you can offer.
From: Lou on 22 May 2010 10:40 "Steve" <steve.doig(a)asu.edu> wrote in message news:7a126e58-68ca-4561-b8b4-290cc6b8182e(a)u3g2000prl.googlegroups.com... (snipped) > Unfortunately, it's been 15 years since I've done any serious SAS > programming, though I > have v. 9.2 handy (but no SAS docs around). If you have a SAS installation you can use, chances are that you have the online help available, which is pretty much word for word what you'd find in the printed docs. If the online help is not installed, you can always see it on the web at http://support.sas.com/documentation/onlinedoc/91pdf/index.html (if you really need the docs for 9.2, click on the link in the left pane).
From: Steve on 22 May 2010 20:47 Thanks to Tom's second idea and Lou's pointer to the SAS docs, I cobbled together some code that now works fine.
From: RolandRB on 24 May 2010 08:12 On 22 Mai, 04:53, Steve <steve.d...(a)asu.edu> wrote: > I have a long text file where each line represents one of 10 different > text or date variables. Each variable line starts with its own > identifier (like Recnum: or Start_Date:). The variable RECNUM > indicates the start of a new 10-line record; the variable Final is the > last one in the record. At each encounter of RECNUM I want to loop > through the variables until I hit another RECNUM, and then output the > 10 variables into one record, then do it again for all 600 records in > the text. > > Unfortunately, it's been 15 years since I've done any serious SAS > programming, though I > have v. 9.2 handy (but no SAS docs around). Can someone point me to a > sample program that does the following: > -- Steps through a text file with multiple lines for each record, with > each line representing one variable; > -- Uses IF-THEN-ELSE statements to read the start of each line to > detect which variable is being read and saved; > -- Outputs the record into a SAS dataset once the last line in a > record has been read; > -- Then clears all the variables and does the above over again at the > beginning of the next record in the text, until all records are read. > > I know it's pretty simple because I've written programs like this in > the distant past. But I don't remember the details of the necessary @s > and RETAINs and such. So thanks for any guidance you can offer. Like this: data test; input @'Recnum: ' recnum @'Start_date: ' date ddmmyy10. @'Final: ' final; format data date9.; datalines; Recnum: 1 Start_date: 23/10/1954 Final: 9 Recnum: 2 Start_date: 23/05/2010 Final: 999 ;;;; run; options nocenter nodate nonumber; proc print data=test; run;
From: RolandRB on 24 May 2010 15:43 On 24 Mai, 14:12, RolandRB <rolandbe...(a)hotmail.com> wrote: > On 22 Mai, 04:53, Steve <steve.d...(a)asu.edu> wrote: > > > > > > > I have a long text file where each line represents one of 10 different > > text or date variables. Each variable line starts with its own > > identifier (like Recnum: or Start_Date:). The variable RECNUM > > indicates the start of a new 10-line record; the variable Final is the > > last one in the record. At each encounter of RECNUM I want to loop > > through the variables until I hit another RECNUM, and then output the > > 10 variables into one record, then do it again for all 600 records in > > the text. > > > Unfortunately, it's been 15 years since I've done any serious SAS > > programming, though I > > have v. 9.2 handy (but no SAS docs around). Can someone point me to a > > sample program that does the following: > > -- Steps through a text file with multiple lines for each record, with > > each line representing one variable; > > -- Uses IF-THEN-ELSE statements to read the start of each line to > > detect which variable is being read and saved; > > -- Outputs the record into a SAS dataset once the last line in a > > record has been read; > > -- Then clears all the variables and does the above over again at the > > beginning of the next record in the text, until all records are read. > > > I know it's pretty simple because I've written programs like this in > > the distant past. But I don't remember the details of the necessary @s > > and RETAINs and such. So thanks for any guidance you can offer. > > Like this: > > data test; > input @'Recnum: ' recnum @'Start_date: ' date ddmmyy10. @'Final: ' > final; > format data date9.; > datalines; > Recnum: 1 > Start_date: 23/10/1954 > Final: 9 > Recnum: 2 > Start_date: 23/05/2010 > Final: 999 > ;;;; > run; > options nocenter nodate nonumber; > proc print data=test; > run;- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - I should point out that thse identifiers would have to all exist and in the same order for code like mine to work. The reason I submitted it is because a lot of sas programmers are not aware of input using labels as I am illustrating.
|
Next
|
Last
Pages: 1 2 Prev: Finding the variables with all missing values Next: Proc logistic: how to add constraints on variables? |