BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nyfaria
Fluorite | Level 6
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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
carrieforeman
Fluorite | Level 6

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;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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?

carrieforeman
Fluorite | Level 6

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;
carrieforeman
Fluorite | Level 6

No problem, glad I could help 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1126 views
  • 2 likes
  • 3 in conversation