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 🙂
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.