BookmarkSubscribeRSS Feed
nickb
Calcite | Level 5
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;
2 REPLIES 2
ArtC
Rhodochrosite | Level 12
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]
nickb
Calcite | Level 5
Worked great. Thanks a bunch.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1007 views
  • 0 likes
  • 2 in conversation