BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jude1
Fluorite | Level 6

I'm new to sas, and trying to learn. In an exercise I'm doing, I'm given ID, date, suger level in my data. i am asked to Output all observations after the first for each person to a dataset. Do i use an if then else statement? 

Also, how do i output all observations for patients with only one record to a dataset

Here is my code for first which i figured. I just can not figure out the code for observations after the first:

 

proc import
datafile='patient2.xlsx'
dbms=xlsx replace out=patients;
sheet="Sheet1"; getnames=yes;
proc sort data=patients; by patient date;
run;

data patientsObs;
set patients; by patient Date;
if first.patient then output;
rename suger = firstobs;

proc print data=patientsObs;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
qoit
Pyrite | Level 9

Hope the below helps:

 

/* Read the object spawner log */
data have;
	input patient $ date date9. s_level;
	format date date9.;
	datalines;
01 01jan2021 7
01 05jan2021 8
01 14jan2021 7
02 01jan2021 7
02 04jan2021 6
02 28jan2021 10
02 29jan2021 12
03 01feb2021 2
03 02feb2021 6
;
run;

proc sort data=have;
	by patient date;
run;

data want;
	set have;
	by patient date;

	if ^first.patient then
		output;
run;

View solution in original post

2 REPLIES 2
qoit
Pyrite | Level 9

Hope the below helps:

 

/* Read the object spawner log */
data have;
	input patient $ date date9. s_level;
	format date date9.;
	datalines;
01 01jan2021 7
01 05jan2021 8
01 14jan2021 7
02 01jan2021 7
02 04jan2021 6
02 28jan2021 10
02 29jan2021 12
03 01feb2021 2
03 02feb2021 6
;
run;

proc sort data=have;
	by patient date;
run;

data want;
	set have;
	by patient date;

	if ^first.patient then
		output;
run;
jude1
Fluorite | Level 6
Thank you so much. I tried so many if then statements, and could not figure it out. It is way simpler than i imagined. Much appreciated.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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