data Females;
input @14 Gender $1. @;
if Gender ne 'F' then delete;
input @1 Subj $3.
@4 DOB mmddyy10.
@15 Balance 7.;
datalines;
00110/21/1955M 1145
00211/18/2001F 18722
00305/07/1944M 123.45
00407/25/1945F -12345
;
proc print data = Females;
run;
when I remove @ after input statement(input @14 Gender $1 @), the output as above , why
I am not sure what you mean by "is wrong".
The first example the @ at the end of the first Input statement holds the input pointer after the the value for Gender is read.
You might try running this version of the code:
data Females; input @14 Gender $1.; put 'After first input ' _all_; if Gender ne 'F' then delete; put 'After delete ' _all_; input @1 Subj $3. @4 DOB mmddyy10. @15 Balance 7.; put 'After second Input ' _all_; datalines; 00110/21/1955M 1145 00211/18/2001F 18722 00305/07/1944M 123.45 00407/25/1945F -12345 ;
Which generates these lines in the log:
After first input Gender=M Subj= DOB=. Balance=. _ERROR_=0 _N_=1 After first input Gender=F Subj= DOB=. Balance=. _ERROR_=0 _N_=2 After delete Gender=F Subj= DOB=. Balance=. _ERROR_=0 _N_=2 After second Input Gender=F Subj=003 DOB=-5717 Balance=123.45 _ERROR_=0 _N_=2 After first input Gender=F Subj= DOB=. Balance=. _ERROR_=0 _N_=3 After delete Gender=F Subj= DOB=. Balance=. _ERROR_=0 _N_=3 NOTE: LOST CARD. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-- 771 ; Gender=F Subj= DOB=. Balance=. _ERROR_=1 _N_=3
Two pieces that are pretty important note that the Subj=003 I highlighted? That is because before the data was written the second INPUT executed and read from the next line (the third) because the second data line was discarded as already ready after the first input. And after that Input the read buffer presents the 4th line of data to be read which is what the First input sees. After reading the F in the 4th line it again discards the current line and prepares to read the next with second Input statement. But that is attempting to read past the end of the data
There is only ONE output record because the attempt to read past the end of the data causes an error.
You did see that "lost card" in your log didn't you?
The _n_ in the log is the iteration of the data step
I think that if remove @, SAS go through step by step as following:
1: input @14 Gender $1 —— get M
2: judge the value ——M, and delete the first row (001 01/21/1955 M 1145)
3: now the pointer at the second row (because remove @)
4:the code (input @1 Subj $3
@4 DOB mmddyy10.
@15 Balance 7.; ) read the data in the second row ;
where is wrong?
I am not sure what you mean by "is wrong".
The first example the @ at the end of the first Input statement holds the input pointer after the the value for Gender is read.
You might try running this version of the code:
data Females; input @14 Gender $1.; put 'After first input ' _all_; if Gender ne 'F' then delete; put 'After delete ' _all_; input @1 Subj $3. @4 DOB mmddyy10. @15 Balance 7.; put 'After second Input ' _all_; datalines; 00110/21/1955M 1145 00211/18/2001F 18722 00305/07/1944M 123.45 00407/25/1945F -12345 ;
Which generates these lines in the log:
After first input Gender=M Subj= DOB=. Balance=. _ERROR_=0 _N_=1 After first input Gender=F Subj= DOB=. Balance=. _ERROR_=0 _N_=2 After delete Gender=F Subj= DOB=. Balance=. _ERROR_=0 _N_=2 After second Input Gender=F Subj=003 DOB=-5717 Balance=123.45 _ERROR_=0 _N_=2 After first input Gender=F Subj= DOB=. Balance=. _ERROR_=0 _N_=3 After delete Gender=F Subj= DOB=. Balance=. _ERROR_=0 _N_=3 NOTE: LOST CARD. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-- 771 ; Gender=F Subj= DOB=. Balance=. _ERROR_=1 _N_=3
Two pieces that are pretty important note that the Subj=003 I highlighted? That is because before the data was written the second INPUT executed and read from the next line (the third) because the second data line was discarded as already ready after the first input. And after that Input the read buffer presents the 4th line of data to be read which is what the First input sees. After reading the F in the 4th line it again discards the current line and prepares to read the next with second Input statement. But that is attempting to read past the end of the data
There is only ONE output record because the attempt to read past the end of the data causes an error.
You did see that "lost card" in your log didn't you?
The _n_ in the log is the iteration of the data step
This is what I need . Thank you so much.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.