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

Hello all,

I am using SAS base 9.4 M5 on enterprise guide 7.15 HF7. I have a HL7 file where I am getting multiple observations for diagnosis with incremental Set_ID for one person. I want to group all these observations per person and assign numbers so that I can de-normalize the data. The maximum number of observations per person(visit) is 12 in my source file.

 

Input dataset:

 

Segment_Type_ID       Set_ID_DG1          Diagnosis_Coding_Method          Diagnosis_Code
DG1                                       1                                    ICD                                          E559
DG1                                       2                                    ICD                                          E039
DG1                                       3                                    ICD                                          I10
DG1                                       4                                    ICD                                          R7301
DG1                                       5                                    ICD                                          R5383
DG1                                       1                                    ICD                                          R079
DG1                                       1                                    ICD                                          E782
DG1                                       2                                    ICD                                          Z6841
DG1                                       3                                    ICD                                          I10
DG1                                       4                                    ICD                                          Z125

 

 

I want the output to be like this:

 

Segment_Type_ID       Set_ID_DG1          Diagnosis_Coding_Method          Diagnosis_Code      visit_no
DG1                                       1                                    ICD                                          E559                 1
DG1                                       2                                    ICD                                          E039                 1
DG1                                       3                                    ICD                                          I10                    1
DG1                                       4                                    ICD                                          R7301               1
DG1                                       5                                    ICD                                          R5383               1
DG1                                       1                                    ICD                                          R079                 2
DG1                                       1                                    ICD                                          E782                 3
DG1                                       2                                    ICD                                          Z6841               3
DG1                                       3                                    ICD                                          I10                    3
DG1                                       4                                    ICD                                          Z125                 3

 

 

I have used the following code but failed to get the desired output as it fails to capture maximum value per visit in the  Set_ID_DG1 variable:

 

data DG1_want;
set WORK.DG1_have;
retain count_up_by_12 rowcount 1;
if first.Set_ID_DG1 then do;
count_up_by_12=1;
rowcount=1;
end;
else rowcount+1;
output;
if mod(rowcount,12)=1 then count_up_by_12+1;
drop rowcount;
run;

 

 

Please, any suggestions ? Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @mosabbirfardin 

 

Are you asking for 

 

data DG1_want;
set WORK.DG1_have;
if set_id_dg1=1 then visit_no+1;
run;

 

View solution in original post

6 REPLIES 6
mosabbirfardin
Fluorite | Level 6

Hello all,

I am using SAS base 9.4 M5 on enterprise guide 7.15 HF7. I have a HL7 file where I am getting multiple observations for diagnosis with incremental Set_ID for one person. I want to group all these observations per person and assign numbers so that I can de-normalize the data. The maximum number of observations per person(visit) is 12 in my source file.

 

Input dataset:

 

Segment_Type_ID       Set_ID_DG1          Diagnosis_Coding_Method          Diagnosis_Code
DG1                                       1                                    ICD                                          E559
DG1                                       2                                    ICD                                          E039
DG1                                       3                                    ICD                                          I10
DG1                                       4                                    ICD                                          R7301
DG1                                       5                                    ICD                                          R5383
DG1                                       1                                    ICD                                          R079
DG1                                       1                                    ICD                                          E782
DG1                                       2                                    ICD                                          Z6841
DG1                                       3                                    ICD                                          I10
DG1                                       4                                    ICD                                          Z125

 

 

I want the output to be like this:

 

Segment_Type_ID       Set_ID_DG1          Diagnosis_Coding_Method          Diagnosis_Code      visit_no
DG1                                       1                                    ICD                                          E559                 1
DG1                                       2                                    ICD                                          E039                 1
DG1                                       3                                    ICD                                          I10                    1
DG1                                       4                                    ICD                                          R7301               1
DG1                                       5                                    ICD                                          R5383               1
DG1                                       1                                    ICD                                          R079                 2
DG1                                       1                                    ICD                                          E782                 3
DG1                                       2                                    ICD                                          Z6841               3
DG1                                       3                                    ICD                                          I10                    3
DG1                                       4                                    ICD                                          Z125                 3

 

 

I have used the following code but failed to get the desired output as it fails to capture maximum value per visit in the  Set_ID_DG1 variable:

 

data DG1_want;
set WORK.DG1_have;
retain count_up_by_12 rowcount 1;
if first.Set_ID_DG1 then do;
count_up_by_12=1;
rowcount=1;
end;
else rowcount+1;
output;
if mod(rowcount,12)=1 then count_up_by_12+1;
drop rowcount;
run;

 

 

Please, any suggestions ? Thanks in advance.

novinosrin
Tourmaline | Level 20

Hi @mosabbirfardin 

 

Are you asking for 

 

data DG1_want;
set WORK.DG1_have;
if set_id_dg1=1 then visit_no+1;
run;

 

novinosrin
Tourmaline | Level 20

@mosabbirfardin   Or more complete

 


data DG1_want;
set WORK.DG1_have;
by Segment_Type_ID ; if first.Segment_Type_ID then visit_no=1; else if set_id_dg1=1 then visit_no+1; run;

 

 

mosabbirfardin
Fluorite | Level 6

Thanks a lot. It worked perfectly!!

Reeza
Super User
Please don't post the same question twice, I've merged them into one for you here.
Reeza
Super User

I think you're overthinking this. If this doesn't work, please expand your sample data to include cases where it fails.

 

data want;
set have;
by segment_type_id notsorted;

retain visit_no;

if first.segment_type_id then visit_no = 0;

if set_id_dg1 = 1 then visit_no+1;

run;


@mosabbirfardin wrote:

Hello all,

I am using SAS base 9.4 M5 on enterprise guide 7.15 HF7. I have a HL7 file where I am getting multiple observations for diagnosis with incremental Set_ID for one person. I want to group all these observations per person and assign numbers so that I can de-normalize the data. The maximum number of observations per person(visit) is 12 in my source file.

 

Input dataset:

 

Segment_Type_ID       Set_ID_DG1          Diagnosis_Coding_Method          Diagnosis_Code
DG1                                       1                                    ICD                                          E559
DG1                                       2                                    ICD                                          E039
DG1                                       3                                    ICD                                          I10
DG1                                       4                                    ICD                                          R7301
DG1                                       5                                    ICD                                          R5383
DG1                                       1                                    ICD                                          R079
DG1                                       1                                    ICD                                          E782
DG1                                       2                                    ICD                                          Z6841
DG1                                       3                                    ICD                                          I10
DG1                                       4                                    ICD                                          Z125

 

 

I want the output to be like this:

 

Segment_Type_ID       Set_ID_DG1          Diagnosis_Coding_Method          Diagnosis_Code      visit_no
DG1                                       1                                    ICD                                          E559                 1
DG1                                       2                                    ICD                                          E039                 1
DG1                                       3                                    ICD                                          I10                    1
DG1                                       4                                    ICD                                          R7301               1
DG1                                       5                                    ICD                                          R5383               1
DG1                                       1                                    ICD                                          R079                 2
DG1                                       1                                    ICD                                          E782                 3
DG1                                       2                                    ICD                                          Z6841               3
DG1                                       3                                    ICD                                          I10                    3
DG1                                       4                                    ICD                                          Z125                 3

 

 

I have used the following code but failed to get the desired output as it fails to capture maximum value per visit in the  Set_ID_DG1 variable:

 

data DG1_want;
set WORK.DG1_have;
retain count_up_by_12 rowcount 1;
if first.Set_ID_DG1 then do;
count_up_by_12=1;
rowcount=1;
end;
else rowcount+1;
output;
if mod(rowcount,12)=1 then count_up_by_12+1;
drop rowcount;
run;

 

 

Please, any suggestions ? Thanks in advance.


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 6 replies
  • 1266 views
  • 2 likes
  • 3 in conversation