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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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