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]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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