I need to make table A into Table b:
Question 1: Convert the multiple record per patient table to one record per patient
Table A
|
Table B
|
This is my code so far:
OPTION PS= 58 LS= 72 NODATE NONUMBER;
DATA DM2022.Patients;
SET patientsdata;
By emplid;
Run;
PROC PRINT data= patients NOOBS;
title 'Table B';
RUN;
DATA Patients;
INPUT EmpID 1-4 Jan 6 Feb 8 March 10 April 12 May 14 June 16;
DATALINES;
1001 0 1 0 0 1 .
1001 . 0 0 0 0 0
1001 . 0 . 1 0 0
1001 0 1 0 0 . 0
1001 1 1 0 0 0 1
1002 1 1 1 1 0 0
1002 0 0 0 0 0 1
1003 1 1 . 1 0 0
1003 . 0 0 0 0 0
1003 0 0 . . 0 .
1004 . 1 0 0 0 0
1004 1 1 0 0 0 0
1004 1 . 0 0 0 0
1004 0 1 1 1 0 0
;
RUN;
*summarize each ID to one row per ID taking the maximum value for each month;
proc means data=patients noprint NWAY;
class empID;
var Jan--June;
output out=grouped_data max = ;
run;
*display results from summarization step;
proc print data=grouped_data;
run;
The above works as expected. I'm not sure what the rest of your code was intended to do, therefore not sure if it's needed.
I don't know what you were inten
Take the maximum of each column grouping by ID
proc means data=dm2022.patients noprint NWAY;
class emplID;
var Jan--June;
output out=grouped_data max = ;
run;
I have questions about your code though...
Is your data/set statement backwards in the code you posted? And then no libraries reference in the print although it is assigned it to a library?
The options specified at the top of the code are usually seen in older SAS code that used the listing output not HTML one. Some of those do not apply to ODS HTML if that is the destination (displayed results file format).
@mcalde33 wrote:
I need to make table A into Table b:
Question 1: Convert the multiple record per patient table to one record per patient
Table A
Emp Id
Jan
Feb
March
April
May
June
1001
0
1
0
0
1
.
1001
.
0
0
0
0
0
1001
.
0
.
1
0
0
1001
0
1
0
0
.
0
1001
1
1
0
0
0
1
1002
1
1
1
1
0
0
1002
0
0
0
0
0
1
1003
1
1
.
1
0
0
1003
.
0
0
0
0
0
1003
0
0
.
.
0
.
1004
.
1
0
0
0
0
1004
1
1
0
0
0
0
1004
1
.
0
0
0
0
1004
0
1
1
1
0
0
Table B
Emp Id
Jan
Feb
March
April
May
June
1001
1
1
0
1
1
1
1002
1
1
1
1
0
1
1003
1
1
0
1
0
0
1004
1
1
1
1
0
0
This is my code so far:
OPTION PS= 58 LS= 72 NODATE NONUMBER;
DATA DM2022.Patients;
SET patientsdata;
By emplid;
Run;
PROC PRINT data= patients NOOBS;
title 'Table B';
RUN;
No it did not.
Here is my code:
Table B
1001 | 0 | 1 | 0 | 0 | 1 | . |
1001 | . | 0 | 0 | 0 | 0 | 0 |
1001 | . | 0 | . | 1 | 0 | 0 |
1001 | 0 | 1 | 0 | 0 | . | 0 |
1001 | 1 | 1 | 0 | 0 | 0 | 1 |
1002 | 1 | 1 | 1 | 1 | 0 | 0 |
1002 | 0 | 0 | 0 | 0 | 0 | 1 |
1003 | 1 | 1 | . | 1 | 0 | 0 |
1003 | . | 0 | 0 | 0 | 0 | 0 |
1003 | 0 | 0 | . | . | 0 | . |
1004 | . | 1 | 0 | 0 | 0 | 0 |
1004 | 1 | 1 | 0 | 0 | 0 | 0 |
1004 | 1 | . | 0 | 0 | 0 | 0 |
1004 | 0 | 1 | 1 | 1 | 0 | 0 |
It's not working because the data doesn't exist though - not an issue with the code.
What is the name of the input data set?
Please show a proc contents on that data, e.g.
proc contents data=patientsData;
run;
The code you posted is not relevant to the question being asked, but if it doesn't work then the next steps will not work.
This is what im using to "set" the data.
DATA Patients;
INPUT EmpID 1-4 Jan 6 Feb 8 March 10 April 12 May 14 June 16;
DATALINES;
1001 0 1 0 0 1 .
1001 . 0 0 0 0 0
1001 . 0 . 1 0 0
1001 0 1 0 0 . 0
1001 1 1 0 0 0 1
1002 1 1 1 1 0 0
1002 0 0 0 0 0 1
1003 1 1 . 1 0 0
1003 . 0 0 0 0 0
1003 0 0 . . 0 .
1004 . 1 0 0 0 0
1004 1 1 0 0 0 0
1004 1 . 0 0 0 0
1004 0 1 1 1 0 0
;
RUN;
DATA Patients;
INPUT EmpID 1-4 Jan 6 Feb 8 March 10 April 12 May 14 June 16;
DATALINES;
1001 0 1 0 0 1 .
1001 . 0 0 0 0 0
1001 . 0 . 1 0 0
1001 0 1 0 0 . 0
1001 1 1 0 0 0 1
1002 1 1 1 1 0 0
1002 0 0 0 0 0 1
1003 1 1 . 1 0 0
1003 . 0 0 0 0 0
1003 0 0 . . 0 .
1004 . 1 0 0 0 0
1004 1 1 0 0 0 0
1004 1 . 0 0 0 0
1004 0 1 1 1 0 0
;
RUN;
*summarize each ID to one row per ID taking the maximum value for each month;
proc means data=patients noprint NWAY;
class empID;
var Jan--June;
output out=grouped_data max = ;
run;
*display results from summarization step;
proc print data=grouped_data;
run;
The above works as expected. I'm not sure what the rest of your code was intended to do, therefore not sure if it's needed.
I don't know what you were inten
proc means data=patients noprint NWAY;
class empID;
var Jan--June;
output out=grouped_data (drop = _freq_ _type_) max = ;
run;
Use a dataset drop option to drop the variables in the proc means step.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.