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-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!

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.

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