Hi,
I'm getting the following errors on running my code:
ERROR: Alphabetic prefixes for enumerated variables (HEADER_DIAGNOSIS_1_CODE-HEADER_DIAGNOSIS_25_CODE) are different.
ERROR: Too few variables defined for the dimension(s) specified for the array Diag.
/**** Pulling Patients ***/
Data AC_1 (keep = a b c);
set abc;
array Diag {28} $ HEADER_DIAGNOSIS_1_CODE-HEADER_DIAGNOSIS_25_CODE;
RespInd = 0;
do i = 1 to dim(Diag);
If Diag {i} in ('E850','E851', 'E852','E853','E854','E858','E8589','E859') then RespInd = 1;
end;
drop i;
run;
Please help!
No text is allowed after the numbers if you want to use ranges that way. If you don't have any other variable starting with "header_diagnosis_", try using
array Diag {28} $ HEADER_DIAGNOSIS_:;
Now, I got this error:
array Diag {26} $ HEADER_DIAGNOSIS_:;
ERROR: Too few variables defined for the dimension(s) specified for the array Diag.
Thanks, it is working but it is taking too much time as compared to Proc sql when I declared 26 variables there.
Thanks!
@AmitChop7391 wrote:
Thanks, it is working but it is taking too much time as compared to Proc sql when I declared 26 variables there.
Thanks!
Can't believe, that in that case a data-step is slower that proc sql. Please post the code.
Data AC_1;
set abc (keep = HEADER_DIAGNOSIS_1_CODE
HEADER_DIAGNOSIS_2_CODE
HEADER_DIAGNOSIS_3_CODE
HEADER_DIAGNOSIS_4_CODE
HEADER_DIAGNOSIS_5_CODE
HEADER_DIAGNOSIS_6_CODE
HEADER_DIAGNOSIS_7_CODE
HEADER_DIAGNOSIS_8_CODE
HEADER_DIAGNOSIS_9_CODE
HEADER_DIAGNOSIS_10_CODE
HEADER_DIAGNOSIS_11_CODE
HEADER_DIAGNOSIS_12_CODE
HEADER_DIAGNOSIS_13_CODE
HEADER_DIAGNOSIS_14_CODE
HEADER_DIAGNOSIS_15_CODE
HEADER_DIAGNOSIS_16_CODE
HEADER_DIAGNOSIS_17_CODE
HEADER_DIAGNOSIS_18_CODE
HEADER_DIAGNOSIS_19_CODE
HEADER_DIAGNOSIS_20_CODE
HEADER_DIAGNOSIS_21_CODE
HEADER_DIAGNOSIS_22_CODE
HEADER_DIAGNOSIS_23_CODE
HEADER_DIAGNOSIS_24_CODE
HEADER_DIAGNOSIS_25_CODE
);
array Diag {*} $ HEADER_DIAGNOSIS_:;
RespInd = 0;
do i = 1 to dim(Diag);
If Diag {i} in ('E850','E851', 'E852','E853','E854','E858','E8589','E859') then RespInd = 1;
end;
drop i;
run;
Remember, you can se the colon operator in the keep= option as well.
Also, I think the IN Operator in
If Diag {i} in ('E850','E851', 'E852','E853','E854','E858','E8589','E859') then RespInd = 1;
is what slows things down. You are probably better off using the INDEX or FIND function.
Try flipping the question. You could also unroll the iteration over E array.
data have;
infile cards dsd missover;
id + 1;
input (Header_diagnosis_1-Header_diagnosis_6)(:$6.);
cards;
E850,E851, E853,E854,E858
E850,E851, E858
G850,C851, D858
;;;;
run;
proc print;
run;
data respint;
set have;
array Diag [*] $ HEADER_DIAGNOSIS_:;
array e[8] $5 _temporary_ ('E850','E851', 'E852','E853','E854','E858','E8589','E859');
RespInd = 0;
do i = 1 to dim(e);
if e[i] in diag then do;
RespInd = 1;
leave;
end;
end;
drop i;
run;
proc print;
run;
Good suggestion, but note that buried in the logic is the LEAVE statement. You could get similar savings to the LEAVE statement by changing your original DO loop:
do i = 1 to dim(Diag) until (respind=1);
That way, once a match is found, you won't need to check the remaining diagnosis codes.
I am still wondering what proc sql code creates the result dataset faster then the data-step using leave or until.
@Astounding wrote:
Good suggestion, but note that buried in the logic is the LEAVE statement. You could get similar savings to the LEAVE statement by changing your original DO loop:
do i = 1 to dim(Diag) until (respind=1);
That way, once a match is found, you won't need to check the remaining diagnosis codes.
I think it called the "same difference".
Hey,
I need to check those codes in all diagnosis fields i.e Diagnosis_1 - Diagnosis_26.
Thanks,
Amit
No, that's wrong.
Once you find a match and set RespInd=1, you no longer need to check the remaining diagnosis codes. All that would do is allow you to set RespInd to 1, when it is already 1.
Thanks, I will try this one.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.