BookmarkSubscribeRSS Feed
AmitChop7391
Obsidian | Level 7

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!

14 REPLIES 14
andreas_lds
Jade | Level 19

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_:;
AmitChop7391
Obsidian | Level 7

Now, I got this error: 

 

array Diag {26} $ HEADER_DIAGNOSIS_:;
ERROR: Too few variables defined for the dimension(s) specified for the array Diag.

AmitChop7391
Obsidian | Level 7

Thanks, it is working but it is taking too much time as compared to Proc sql when I declared 26 variables there.

 

Thanks!

andreas_lds
Jade | Level 19

@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.

AmitChop7391
Obsidian | Level 7

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;

PeterClemmensen
Tourmaline | Level 20

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.

data_null__
Jade | Level 19

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;

 

Capture.PNG

Astounding
PROC Star

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.

andreas_lds
Jade | Level 19

I am still wondering what proc sql code creates the result dataset faster then the data-step using leave or until.

data_null__
Jade | Level 19

@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".

AmitChop7391
Obsidian | Level 7

Hey,

 

I need to check those codes in all diagnosis fields i.e Diagnosis_1 - Diagnosis_26.

 

Thanks,

Amit

Astounding
PROC Star

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.

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!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 14 replies
  • 9012 views
  • 1 like
  • 5 in conversation