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

Using SAS EG to create an array transforming 24 character diagnosis codes to numeric. This is what I have so far and it does not work. I believe it has to do with defining the _num array. Not sure how to do this?

 

DATA dxcodes2;

SET dxcodes;

ARRAY _char (24) dx2-dx25;

ARRAY _num (24) dx2-dx25;

DO i to 24;

_num{i} = input(_char{i},best8.);

END;

RUN;

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

DATA dxcodes2;

SET dxcodes;

ARRAY _char (24) dx2-dx25;

ARRAY _num (24) _dx2 - _dx25;

DO i=1  to 24;

_num{i} = input(_char{i}, 8.);

END;

RUN;

 

Basically you can't change the datatype of the existing char vars. You need another set of numeric array

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

DATA dxcodes2;

SET dxcodes;

ARRAY _char (24) dx2-dx25;

ARRAY _num (24) _dx2 - _dx25;

DO i=1  to 24;

_num{i} = input(_char{i}, 8.);

END;

RUN;

 

Basically you can't change the datatype of the existing char vars. You need another set of numeric array

Reeza
Super User

1. You cannot do in place conversion, a variable cannot be changed from numeric to character or vice versa so you need to create a new variable. 

2. Diagnosis codes usually have a letter as well as codes, so be careful. 

Krysia24
Obsidian | Level 7

So the reason I had originally wanted to change all the dx codes to numeric is because I tried the substring function to extract any ICD9 codes of '090' but was ending up with people whose code was 90_ (so like 902, 909 as examples). It's as if the zero was not being counted and I thought that maybe it had to do with the dx variables being character. This was the original code that was pulling incorrect codes - any insight is appreciated:

 

ARRAY DX (24) DX2-DX25;
        csyph = 0;
        DO I = 1 TO 24;
        IF SUBSTR(dx{I},1,3) = '090'   THEN csyph = 1;

END;

 

 

Reeza
Super User

Your code looks correct, but the flag is 1, if any in the row is 090.  Without your data, it’s hard to say more. 

 

 

Krysia24
Obsidian | Level 7

I guess what I am trying to go for is if the first three digits of the dx code is EXACTLY = 090 instead of any sort of "090" string within the dx code existing. Does that make sense?

Reeza
Super User

Your code is correct, so I think you’re seeing some other issue.... that’s resulting in the 09X or the 90X.  

 

DX codes have the letter at the front, so E090 would not match. 

ballardw
Super User

@Krysia24 wrote:

So the reason I had originally wanted to change all the dx codes to numeric is because I tried the substring function to extract any ICD9 codes of '090' but was ending up with people whose code was 90_ (so like 902, 909 as examples). It's as if the zero was not being counted and I thought that maybe it had to do with the dx variables being character. This was the original code that was pulling incorrect codes - any insight is appreciated:

 

ARRAY DX (24) DX2-DX25;
        csyph = 0;
        DO I = 1 TO 24;
        IF SUBSTR(dx{I},1,3) = '090'   THEN csyph = 1;

END;

 

 


One of the things to check for sometimes with Zero in comparison failing is to check for the existence of capital letter O. Some fonts/displays the difference between 0 and O can be very difficult.

 

Another thing to check for might be leading blanks. The strip function removes leading and trailing blanks.

IF SUBSTR( strip(dx{I}) ,1,3) = '090'   THEN csyph = 1;

 

And yet another is to verify that the DX variables are in fact character. When you ran the posted code did you get any messages about "numeric values have been converted to character"? Which would indicate that DX are actually numeric and then substr wouldn't work as the conversion to character from numeric that SAS would use would not have a leading zero for the comparison to find.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 6390 views
  • 2 likes
  • 4 in conversation