BookmarkSubscribeRSS Feed
Oleg_L
Obsidian | Level 7
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]
2 REPLIES 2
darrylovia
Quartz | Level 8
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;
Oleg_L
Obsidian | Level 7
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]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1566 views
  • 0 likes
  • 2 in conversation