SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ChuksManuel
Pyrite | Level 9

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. 

 

 

ChuksManuel_0-1669585655701.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26

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

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1 reply
  • 817 views
  • 0 likes
  • 2 in conversation