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 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 557 views
  • 2 likes
  • 3 in conversation