SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
charleenjm
Calcite | Level 5

Hi I'm new to coding HCUP data in SAS. I am using ICD10 codes but it seems, but it seems like SAS is not accepting the characters. For instance the variable name is |10_DX1 but I get an error message any time that I use it. I am looking for ICD 10 codes specific to deliveries. The code below doesn't seem to work. How to I find ICD10 codes specific to deliveries? I am using SAS v9.4 on JupyterLab.

 

data = NY2016_deliveries;

    set NY2016; 

    delivery_flag = 0;

     array dx_vars {*} DX1-DX25;

     do i = 1 to dim (dx_vars);

     if substr(dx_vars[i], 1, 3) in; 

     ('O60', 'O61',)

      delivery_flag=1;

      leave;

      end;  

      end;

run;

10 REPLIES 10
Kurt_Bremser
Super User

ALWAYS post the log when you have issues.

 

This looks wrong:

 data = NY2016_deliveries;

A DATA statement does not have an equal sign apart from those needed in additional options.

quickbluefish
Barite | Level 11
 
data NY2016_deliveries;
set NY2016; 
length delivery_flag dxpos 3 dx $10;
delivery_flag = 0;
dxpos=.;
dx=' ';
array dx_vars {*} DX1-DX25;
do i = 1 to dim(dx_vars);
    if substr(dx_vars[i], 1, 3) in ('O60', 'O61') then do;
        delivery_flag=1;
        dxpos=i;
        dx=dx_vars[i];
        output;
        leave;
    end;  
end;
drop i dx1-dx-25;
run;
quickbluefish
Barite | Level 11
This keeps only rows that have a delivery dx. If you want to keep all rows regardless of whether they have a dx of interest, remove the 'output' statement.
ballardw
Super User

It would be very good idea that when posting code related to problems to post a log of the complete step in question. That means for a data step question start at Data and stop with the notes, warnings and or error messages at the end. For a procedure start at the Proc statement.

 

That means we don't have to ask questions like "Is the syntax of the DROP statement you show actually what you submiited?"

data NY2016_deliveries;
set NY2016; 
length delivery_flag dxpos 3 dx $10;
delivery_flag = 0;
dxpos=.;
dx=' ';
array dx_vars {*} DX1-DX25;
do i = 1 to dim(dx_vars);
    if substr(dx_vars[i], 1, 3) in ('O60', 'O61') then do;
        delivery_flag=1;
        dxpos=i;
        dx=dx_vars[i];
        output;
        leave;
    end;  
end;
drop i dx1-dx-25;
run;

Your code as shown does not execute at all it would throw

17   drop i dx1-dx-25;
                  -
                  22
                  76
ERROR 22-322: Syntax error, expecting one of the following: a name, ;,
              _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 76-322: Syntax error, statement will be ignored.

Including all the notes and messages would also provide answers to the problems that will arise if any of the DX1 through DX25 variables are numeric.

 

 

quickbluefish
Barite | Level 11

@ballardw - yup, that one was my mistake (in the DROP statement) - obv. should be:  ...-dx25   rather than:  ...-dx-25.  

charleenjm
Calcite | Level 5

This seemed to work: 


data SCDNY2016_deliveries;

     set scdny2016;

     length delivery_flag dxpos 3 dx $10;
     delivery_flag = 0;
     dxpos=.;
     array dx_vars {*} I10_DX1-I10_DX25;
     do i = 1 to dim(dx_vars);
     if substr(dx_vars[i], 1, 3) in ('O60', 'O61') then do;
     delivery_flag=1;
     dxpos = i;
     dx = dx_vars[i];
      output;
      leave;
end;
end;
drop i;
run;

proc print data=SCDNY2016_deliveries (obs=10); /*checking the first 10 observations*/

run; 

 

 

charleenjm
Calcite | Level 5

I tried a different approach. The variable name for ICD 10 codes is |10_DX1-|10_DX25. However SAS doesn't accept the | character so I am not sure how to proceed but I tried another way here's the log with error messages:

 

data scdny2016_delivery;
set scdny2016;

delivery_flag = 0;

array dx_vars {*}
I10_DX1 I10_DX2 I10_DX3 I10_DX4 I10_DX5
I10_DX6 I10_DX7 I10_DX8 I10_DX9 I10_DX10
I10_DX11 I10_DX12 I10_DX13 I10_DX14 I10_DX15
I10_DX16 I10_DX17 I10_DX18 I10_DX19 I10_DX20
I10_DX21 I10_DX22 I10_DX23 I10_DX24 I10_DX25;

do i = 1 to dim(dx_vars);
if substr(dx_vars[i], 1, 3) in
('O60', 'O61', 'O62', 'O63', 'O64', 'O65', 'O66', 'O67', 'O68', 'O69',
'O70', 'O71', 'O72', 'O73', 'O74', 'O75', 'O76', 'O77', 'O78', 'O79',
'O80', 'O81', 'O82', 'Z37', 'Z38') then do;

delivery_flag = 1;
leave;
end;
end;
run;

Quentin
Super User

It's very unlikely that you have variables names with a in them, like:  I10_DX1

If you run PROC CONTENTS on your data and look at the list of variables, you see | characters there in the variable name?

The Boston Area SAS Users Group is hosting free webinars!
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.
Tom
Super User Tom
Super User

Why do you think the variable name is |10_DX1 ?  I really doubt that HCUP would name a variable that way.

 

If you do have non-standard variable names you need to use name literals when referencing them in your SAS code.

'|10_DX1'n
charleenjm
Calcite | Level 5

charleenjm_0-1745246512438.png

Yea, I thought it was weird too but changed the character from | to I (uppercase i) and it seems to have worked

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 805 views
  • 2 likes
  • 6 in conversation