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

Hi all,

I have a data of preterm babies born in 2015. Any data before 2015 Oct used ICD-9 and the rest of the data after Oct of the same year uses ICD-10 codes. That is 765: by ICD-9 and P07: by ICD-10

There are multiple possible scenarios where baby is coded to preterm based on his/her weight or gestational age or by both. I'd like to count number of preterm birth diagnosis firstly by weight only, secondly by gestational age only and thirdly by both. Say, my data has 1000 observations and I would like to organize it to 200 babies classified to a preterm by weight only (if in 76501-76509 et.c), 150 by gestational age only (if in 76521-76528 et.c) and the rest 650 babies taking both weight and gestational age based diagnosis (if in (76501-76509) or (76521-76528)) et.c. Most babies suppose to be weighed and termed with gestational age so third group should turn out to be the majority of the cases. However, below code doesn't do any good to help count this overlapped group.

 

Any simple solution fot this? Just to let know, I'm not an expert of macro at all. Solutions in Data step and proc sql would be nice.

 

/*MOCK DATA*/;
data demo; input (var1-var4)($); cards; p0701 p0714 V10 76501 p0731 p0739 76521 b20 p0701 p0739 76527 c20 ; run; /*ACTUAL CODE I TRIED WITH NO SUCCESS*/ data demo1; set demo; array m Main_Diagnosis Other_Diagnosis_1-Other_Diagnosis_50; do over m; if m in :("P0701","P0702","P0703","P0714","P0715","P0716","P0717","P0718","76501","76502","76503","76504","76505","76506","76507","76508","76509","76511",
"76512","76513","76514","76515","76516","76517","76518","76519")
then b=1; else
if m in :("P0721","P0722","P0723","P0724","P0725","P0726",
"P0731","P0732","P0733","P0734","P0735","P0736",
"P0737","P0738","P0739","76521","76522","76523",
"76524","76525","76526","76527","76528") 
then b=2; else
if m in :("P0721","P0722","P0723","P0724","P0725","P0726",
"P0731","P0732","P0733","P0734","P0735","P0736",
"P0737","P0738","P0739","76521","76522","76523",
"76524","76525","76526","76527","76528","P0701",
"P0702","P0703","P0714","P0715","P0716","P0717",
"P0718","76501","76502","76503","76504","76505",
"76506","76507","76508","76509","76511","76512",
"76513","76514","76515","76516","76517","76518",
"76519")
then b=3;
end;
if b=1 then weight=1; else weight=0;
if b=2 then gest=1; else gest=0;
if b=3 then both=1; else both=0;
run;

 Thanks.

 

First obs of data:

proc import 
datafile="..................\demo.csv"
out=have
dbms=csv replace;
getnames=yes;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Not sure what you are and aren't including in your various calculations, but I think you are trying to separate the records based on something like:

/*MOCK DATA*/;data demo;
input (Main_Diagnosis Other_Diagnosis_1-Other_Diagnosis_3)($);
cards;
p0701 p0714 V10 76501
p0731 p0739 76521 b20
p0701 p0739 76527 c20
;
run;
/*ACTUAL CODE I TRIED WITH NO SUCCESS*/
data demo1; set demo;
  array m Main_Diagnosis Other_Diagnosis:; 
  x=0;
  y=0;
  do over m;
    if upcase(m) in ("P0701","P0702","P0703","P0714","P0715","P0716","P0717","P0718",
             "76501","76502","76503","76504","76505","76506","76507","76508","76509",
             "76511","76512","76513","76514","76515","76516","76517","76518","76519") then x=1;
  
    if upcase(m) in ("P0721","P0722","P0723","P0724","P0725","P0726",
             "P0731","P0732","P0733","P0734","P0735","P0736",
             "P0737","P0738","P0739","76521","76522","76523",
             "76524","76525","76526","76527","76528") then y=1;
  end;
  if x and y then group=3;
  else if x then group=1;
  else if y then group=2;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

Not sure what you are and aren't including in your various calculations, but I think you are trying to separate the records based on something like:

/*MOCK DATA*/;data demo;
input (Main_Diagnosis Other_Diagnosis_1-Other_Diagnosis_3)($);
cards;
p0701 p0714 V10 76501
p0731 p0739 76521 b20
p0701 p0739 76527 c20
;
run;
/*ACTUAL CODE I TRIED WITH NO SUCCESS*/
data demo1; set demo;
  array m Main_Diagnosis Other_Diagnosis:; 
  x=0;
  y=0;
  do over m;
    if upcase(m) in ("P0701","P0702","P0703","P0714","P0715","P0716","P0717","P0718",
             "76501","76502","76503","76504","76505","76506","76507","76508","76509",
             "76511","76512","76513","76514","76515","76516","76517","76518","76519") then x=1;
  
    if upcase(m) in ("P0721","P0722","P0723","P0724","P0725","P0726",
             "P0731","P0732","P0733","P0734","P0735","P0736",
             "P0737","P0738","P0739","76521","76522","76523",
             "76524","76525","76526","76527","76528") then y=1;
  end;
  if x and y then group=3;
  else if x then group=1;
  else if y then group=2;
run;

Art, CEO, AnalystFinder.com

 

Cruise
Ammonite | Level 13

Below is my final code:

However, I keep getting error: ERROR: Array subscript out of range at line 535 column 61.

What am I doing wrong? 

 

data want; set have;
array m Diagnosis_1-Other_Diagnosis_34; 
a=0; b=0; c=0; d=0; e=0; f=0; g=0; h=0; i=0; j=0; k=0; l=0; m=0; n=0; o=0; p=0; S=0;
do over m;
if m in :('S05','S0701','S0703') 														then a=1; 
if m in :('S110','S111','S112')                                                         then b=1;  
if m in :('S160','S161','S169','S172') 												    then c=1; 
if m in :('S200') 																		then d=1; 
if m in :('S203','S205','S208') 														then e=1; 
if m in :('S213') 																		then f=1; 
if m in :('S220') 																		then g=1; 
if m in :('S224','S226')  																then h=1; 
if m in :('S234') 																		then i=1; 
if m in :('S251') 																		then j=1; 
if m in :('S262','S263','S264') 														then k=1; 
if m in :('S351','S353','S355','S359') 													then l=1; 
if m in :('S360','S361','S369','S370','S371','S372','S373','S374','S375','S378','S379') then m=1;  
if m in :('S390','S391','S392') 														then n=1; 
if m in :('S71','S72','S73')                                                            then o=1; 
if m in :('S790') 																		then p=1; 
if m in :('S793') 																		then S=1; 
end;
if a then group=1; else if b then group=2; else
if c then group=3; else if d then group=4; else
if e then group=5; else if f then group=6; else
if g then group=7; else if h then group=8; else
if i then group=9; else if j then group=10; else
if k then group=11; else if l then group=12; else
if m then group=13; else if n then group=14; else
if o then group=15; else if p then group=16; else
if S then group=17;
run; 
art297
Opal | Level 21

You're probably getting the error because you are using m as both the array name and one of the variables you are trying to create.

 

Either change the array name to something different, or change the name of the one variable you are currently calling m

 

Art, CEO, AnalystFinder.com

 

 

 

Cruise
Ammonite | Level 13
That was it. Thanks zillions.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1229 views
  • 1 like
  • 2 in conversation