DATA Step, Macro, Functions and more

datalines eof option

Reply
Regular Contributor
Posts: 151

datalines eof option

Hello SAS-users.

If I execute the code below I see that 5 records were written to the file TR:
[pre]
5
24
41
46
46
[/pre]

I want only last value (46) to be written and only once.
I thought that eof option in the infile statement can solve this task. But it is not working as i expected.

Can you suggest how to output only the last value with infile datalines at one datastep.

I use SAS 9.1.3

Thanks in advance.


[pre]

FILENAME tr temp;
data vac_used; retain vac_used 0;
infile datalines eof=nn ;
input date1 :ddmmyy10. date2 :ddmmyy10. holidays :5.;
days1=date2-date1+1-holidays;
vac_used=vac_used+days1;
format date1 date2 date9.;
nn: file tr; put vac_used 5.;
datalines;
18.05.2009 22.05.2009 0
24.08.2009 11.09.2009 0
13.10.2010 29.10.2010 0
27.12.2010 31.12.2010 0
;

[/pre]
Frequent Contributor
Posts: 139

Re: datalines eof option

Since you only want the last record you can use a subsetting if

data vac_used;
retain vac_used 0;
input date1 :ddmmyy10. date2 :ddmmyy10. holidays :5.;
days1=date2-date1+1-holidays;
vac_used=vac_used+days1;
format date1 date2 date9.;

if _n_=4;

put _all_;
datalines;
18.05.2009 22.05.2009 0
24.08.2009 11.09.2009 0
13.10.2010 29.10.2010 0
27.12.2010 31.12.2010 0
;
run;
Regular Contributor
Posts: 151

Re: datalines eof option

Posted in reply to darrylovia
Thanks for your reply.

I've found my mistake. I forget RETURN statement.

[pre]

FILENAME tr temp;
data vac_used; retain vac_used 0;
infile datalines eof=nn ;
input date1 :ddmmyy10. date2 :ddmmyy10. holidays :5.;
days1=date2-date1+1-holidays;
vac_used=vac_used+days1;
format date1 date2 date9.;
return;
nn: file tr; put vac_used 5.;
datalines;
18.05.2009 22.05.2009 0
24.08.2009 11.09.2009 0
13.10.2010 29.10.2010 0
27.12.2010 31.12.2010 0
;

[/pre]
Ask a Question
Discussion stats
  • 2 replies
  • 354 views
  • 0 likes
  • 2 in conversation