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 🙂
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.