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;
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;
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.