Help using Base SAS procedures

Retain statement

Reply
Contributor
Posts: 65

Retain statement

I'm trying to incorporate a retain statement in a data step to display the data a certain way. Below is what the output looks like now:

0715954 --person_id_nb
CHE-120 TR 8:00:00 AM - 9:50:00 AM
**********
0715954
CHE-126 R 10:00:00 AM - 12:15:00 PM
**********

Need it to look like this:
0715954
CHE-120 TR 8:00:00 AM - 9:50:00 AM
CHE-126 R 10:00:00 AM - 12:15:00 PM
**********

Here is the data step that I'm using:
Data _null_;
set work.stud_courses;
*FILE MAX_File;

retain person_id_nb;

format Start_tm timeampm.;
format End_tm timeampm.;



Line1=person_id_nb;
Line2=trim(course_nm) || ' ' || trim(Dayofweek) || '' || put(Start_tm,timeampm.) || ' - ' || put (End_tm,timeampm.);
header_record='**********';

put Line1;
put Line2;
put header_record;

run;
Valued Guide
Posts: 634

Re: Retain statement

Assuming that the incoming data set can be sorted, use a BY statement (following the SET).

[pre]
set work.stud_courses;
by person_id_nb;
[/pre]

then you can use FIRST. and LAST. processing on your PUT statements

[pre]
if first.person_id_nb then put line1;
put line2;
if last.person_id_nb then put header_record;
[/pre]
Contributor
Posts: 65

Re: Retain statement

Worked great. Thanks a bunch.
Ask a Question
Discussion stats
  • 2 replies
  • 133 views
  • 0 likes
  • 2 in conversation