I have a dataset with multiple lines per record. Each record is a healthcare encounter, identified using a combination of health record ID and date of encounter, which appear on the first line, only. I would like to add an Encounter ID variable to all lines of the encounter, and then use proc transpose BY EncounterID to get my diagnosis and procedure data onto the firstline. Here is basically what I've got (hopefully this will format to something legible):
LineNum HlthRecordID City ServiceDate Diagnosis Procedure
Suggest looking at a SAS DATA step with "BY GROUP PROCESSING" where you will have a "counter variable" incremented with each new "condition" which you would define, based on your SAS variables. In your code, you will want to consider using a code piece like:
IF FIRST. THEN DO;
* your assignment logic here ;
possibly using a RETAIN statement to increment your Encounter_ID variable, finally resetting it back to some initial-value with each new "condition".
You will find the SAS support http://support.sas.com/ website, with SAS-hosted DOC and supplemental technical / conference, can provide guidance and code examples. As well, there are forum archives on this topic of creating an "ID variable" for tracking purposes.
Suggested Google advanced search arguments, this topic / post:
data step programming by group processing site:sas.com
Each health system encocunter has several lines of data, with the identifying information, the first diagnosis code and the first procedure code on the first line, while the remaining lines have only the additional diagnosis and procedure codes. I'd like the diagnosis code on the first line to populate a variable called Diag1, the diagnosis code on the second line to populate a variable called Diag2, etc. And likewise with the procedure codes. The final result will be to have the identifying information AND all the diag and proc variables (up to Diag18 and Proc18) on one line per health system encounter.
I haven't had time to try any of the suggestions, yet. Thank you to everyone who has responded!
do until (last);
set inp (keep=id) end=last;
by id notsorted;
if first.id and ^missing(id) then count=1;
do until (n_last);
set inp (rename=(id= old_id City =old_City date=old_date)) end=n_last;
by old_id notsorted;
if first.old_id and ^missing(old_id) and ^missing(lag(Diagnosis)) then output;
if first.old_id and ^missing(old_id) then do;
if n_last then output;
format date_service mmddyy10.;
drop old_id old_City old_date id count n_count Diagnosis Procedure;