data test ;
input @01 Client $10.
@08 Accounts $10.;
format Client $10.
Accounts $10.;
datalines;
Garcia 123456
Gibson 250486
Knapp 123456
Mueller 867530
run;
data _null_;
set test;
if FirstObservation then
put "Start";
put Client || " " || Accounts;
else if LasterObservation then
put Client || " " || Accounts;
put "End"
else
put Client || " " || Accounts;
run;Above is an Example of what I want, but I don't know exactly how I would do it. My wanted output is:
Start
Garcia 123456
Gibson 250486
Knapp 123456
Mueller 867530
End
Any idea how to code this for real?
For the first observation you could use _n_=1 and the last the end=e option on the set statement to flag the end of a data set to be read in. e.g.
data _null_;
set test end=e;
if _n_=1 then do;
put "Start";
put Client || " " || Accounts;
end;
if e then do;
put Client || " " || Accounts;
put "End";
end;
run;
Hi and welcome to the SAS Communities 🙂
This is a fairly easy task. Where do you want this output to go though? In a txt file or the log or?
For the first observation you could use _n_=1 and the last the end=e option on the set statement to flag the end of a data set to be read in. e.g.
data _null_;
set test end=e;
if _n_=1 then do;
put "Start";
put Client || " " || Accounts;
end;
if e then do;
put Client || " " || Accounts;
put "End";
end;
run;
No problem, glad I could help 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.