BookmarkSubscribeRSS Feed
sas_user124
Calcite | Level 5

Hello, so I had a variable called treatmenttype with 3 categories: medication, other, and diet. In a previous step, I used a count function to split this where there are now 3 columns, one for each treatment type. each participant had 2 of the treatment types combined, so this was splitting that out. Now, 

Using proc transpose,

how can I transform each of those treatment categories from wide to long? I want to properly name the new variables and drop what is unneccessary. Once it is done, I want there to be a new treat_type column with medication, other, diet as the option and then a y_n column incidcating whether it was used, with 1 or 0.

 

Please help, I am so confused

1 REPLY 1
ballardw
Super User

At least give us the variable names and types. Better is actual example data as transpose has some tricky behaviors in some cases, like repeats of the ID variable that may cause issues.

 

IF the treatments are all of the same type then something like:

Proc transpose data=have out=trans;
  by id;
  var surgery medication other;
run;

MAY work.

The output if there is a single observation per ID will have variables ID _name_ and Col1 by default. _name_ would have the name of the variable as the value, Surgery Medication or Other and Col1 the value of the original value.

If you have multiple observations per ID then you need really need to provide example data and what expect the resulting output to look like as otherwise you are going to end up with multiple Col variables and that may not match what you want.

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
  • 354 views
  • 0 likes
  • 2 in conversation