☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Pyrite | Level 9

## splitting a variable in SAS

Hello programmers,
I don't know if this title is really what I want to implement, but I will explain. And I'll be glad to get more insight.

I am working on the BRFSS Dataset, and I want to get the number of times per day or week a patient uses a medication.

For example, observations with 301-399 for the variable ILP08_3 recorded their number of times in days, while observations with 401-499 recorded their number of times in weeks.

So if an observation recorded 306, "3" already lets us know we are dealing with a record in days, while "06" indicates the number of times. So, this case used their medication 6 times in a day.

Same way if an observation was recorded as 402. It means that this case used their medication 2 times a week.

What I want to do: I want to be able to split the response into 2. For example, if a response is "306'  for a case with the variable ILP08_3, I want to split it into 2 variables with "3" and "06" (numeric) on different columns.

I appreciate suggestions or referrals.

1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

## Re: splitting a variable in SAS

Let's use simple math. First variable: divide by 100 and then find the integer lower than this result (the FLOOR function). Then the second variable is simply the remainder.

Example:

``````data example;
code=306;
first_variable=floor(code/100);
second_variable=code - first_variable*100;
run;``````
--
Paige Miller
Diamond | Level 26

## Re: splitting a variable in SAS

Let's use simple math. First variable: divide by 100 and then find the integer lower than this result (the FLOOR function). Then the second variable is simply the remainder.

Example:

``````data example;
code=306;
first_variable=floor(code/100);
second_variable=code - first_variable*100;
run;``````
--
Paige Miller
Discussion stats