Similar to--> "Back up" one record during read of complex data set parsing

Similar to--> "Back up" one record during read of complex data set parsing

Post by chang_y_ch » Sat, 11 Sep 2004 06:03:11


n Thu, 9 Sep 2004 15:57:18 -0400, Miller, Jeremy T. < XXXX@XXXXX.COM > wrote:


Hi, Jeremy,

I assume that your input data, dat1, is a sas dataset with two variables,
id and line.

If so, the following will do. The code depends on many other assumptions.
Some of them are:

(1) there are always two blank lines before the question number 1.
(2) a line with "Sent" signals the end of one id's responses.
(3) question number line is always followed by an answer line, which, in
turn, is followed by a blank line.
(4) if the answer is "Other" then it is followed by:
a blank line, a question number line with the same question number,
then a line of comment (only a single line up to 100 chars.), then
finally a blank line.

The sas code uses link, which enables us to get an observation from many
places in the code. if you use multiple set statements outside of link,
then you will end up doing the self-interleaving.

The set statement is wrapped in an always false if-then-do block, in order
to prevent to be executed each time the data step loops. I first saw this
trick mentioned by Dorfman. It is used here to let the sas compiler know
that the variable, line, is of a character type with a length of 100
chars. Then, I cheat with specifying "length id 8" before the block --
just to get the variable order right. ... :-)

Cheers,
Chang

data dat;
infile cards truncover;
length id 8 line $100;
id = 1;
input line $char100.;
cards4;
From: Rpath
Sent: Thursday, March 21, 2002 8:28 PM
To: XXXX@XXXXX.COM
Subject: Survey-Hepatitis B and You

env.HTTP_USER_AGENT
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

1
No

2
No

3
Other

3. Other:
google search engine search

4
Yes

5
Yes

6
Other

6. Comment
can someone just get any hepatitis virus without ....

8
Yes

Sent
Submit Information
;;;;
run;

data dat2;
length id 8 ques 8 answr $5 comment $100;
if 0 then do; /* a hack by Dorfman */
getObs:;
set dat;
if line="Sent" then stop;
return;
end;

if _n_ = 1 then do until (blanks=2);
link getObs;
if missing(line) then blanks + 1;
end;

link getObs;
ques = input(substr(line,1,1), best.);
link getObs;
answr = substr(line,1,5);
if answr = "Other" then do;
link getObs;
link getObs;
if ques ^= input(substr(line,1,1), best.) then do;
put "ERROR: the same question number expected.";
stop;
end; else do;
link getObs;
comment = line;
end;
end;
link getObs;

keep id Ques Answr Comment;
output;
run;

proc print data=dat2 noobs;
run;
/* on lst
id ques answr comment

1 1 No
1 2 No
1 3 Other google search engine search
1 4 Yes
1 5 Yes
1 6 Other can someone just get any hepatitis virus
without ....
1 8 Yes
*/
 
 
 

1. Restore Points - Back Ups >>>>>> ?

2. Mailmerge: <<First Record>> in stead of <<Next Record>>

Hello,
I have a mailmerge document, merging with Exceldata, which start with a
summary of scores on the first page. The following pages show the
detail-information for every recipient on a own page.

1. On the summary (first page) a print the final score; then I skip to the
following recipient with the Wordfield <<Next Record>>
E.g. 10 rows will be filled with information when I finish the mailmerge.

2. The Second page and following show all the subscores of every recipient;
this information uses ONE page for EACH recipient.

MY PROBLEM IS:
The second page I want to start (again) on the first record, because in the
summary I have reached the last record.

So, I want to INSERT MERGEFIELD
- <<First Record>>, so the opposite of <<Next Record>>

How can I fix this problem?
Thank you in advance.
Guus

3. how to read parse data from two file to generate one one file

4. simple thing: from vector<complex<double> > to complex<double> *

5. Need chart of 1 data set plotted against another similar data set

6. How to identify when similar records appear in two sets of data

7. Help with reading in a complex data set

8. Making Matlab read a set of complex data

9. Collect Records from MSSQL one by one into RepeatingTable >> Heeeeeelp

10. Need to map records from one schema to a similar one in sequence

11. How to set two data sets but only keep variables in the first data set

12. Picking only first record from records - QUITE BIG and COMPLEX

13. Data Entry Form (similar to default Excel Data>Form)

14. How do I back-up > truncate > shrink > back-up SQL 2000

15. Picking only first record from records - QUITE BIG and COMPLEX PRO