BookmarkSubscribeRSS Feed
jessho
Calcite | Level 5

Hi all, 

 

I have one variable, patientfeedbackresponse, in my dataset.  I wanted to combine two categories of character variable responses into one (trying to combine 'Retail health clinic' and 'Urgent care center' into a new joint category called 'OSH clinic').  Each time, I try to relabel into a joint variable, I one of the categories comes up as missing.  How would you recommend doing this?


patientfeedbackresponse Frequency Percent CumulativeFrequency CumulativePercent
Done nothing763339.611099557.06
Emergency room2061.071120158.13
N/A701936.421822094.55
Retail health clinic2701.401849095.95
Urgent care center7804.0519270100.00


Thanks

5 REPLIES 5
Reeza
Super User
Use an IF/THEN statement within a data step prior to the PROC FREQ to recode the variable.

Or use a custom format and apply that to the data using PROC FREQ. This option provides more flexibility in the long run.
ballardw
Super User

An example of @Reeza's custom format approach.

proc format library=work;
value $mylist
"Retail health clinic","Urgent care center"="OSH clinic"
;
run;

proc freq data=have;
   tables patientfeedbackresponse;
   format patientfeedbackresponse $mylist.;
run;

This format takes advantage of only formatting the values specified. Anything else not used will appear with the current text.

Of course I don't have your data set name, so use yours on the proc freq statement.

 

Formats used this way create groups as needed. So you could have other formats that combined Emergency room plus these two clinics to a "Any service provider" versus the None and N/A.

jessho
Calcite | Level 5

The if then statements did not work for me, but this proc format command initially did.  However, then when I went to run a regression on the model, it reverted back to the prior separate labels in my logistic regression output.  Is there a command that would change the response labels permanently?

Reeza
Super User

The methods both work, so you likely did something incorrect somewhere or didn't specify the correct option. If you post the code we can show you where that was. Perhaps you simply forgot to apply the label to the data set for the regression?

 

Once you have a format, you can convert it using PUT() but if IF/THEN didn't work, the PUT() conversion won't work either because both are essentially the same approach - recoding the variable. Show your work please.

 


@jessho wrote:

The if then statements did not work for me, but this proc format command initially did.  However, then when I went to run a regression on the model, it reverted back to the prior separate labels in my logistic regression output.  Is there a command that would change the response labels permanently?


 

ballardw
Super User

@jessho wrote:

The if then statements did not work for me, but this proc format command initially did.  However, then when I went to run a regression on the model, it reverted back to the prior separate labels in my logistic regression output.  Is there a command that would change the response labels permanently?


You need to use the Format in the proc logistic.

If you want to permanently assign the format you can do that manually (not recommended but you can) using the tableview or the SAS Exporere display columns. Or Proc Datasets (recommended for existing data sets). Or rerun a data step with the format assignment.

Or just remember to use the format in the other procedures.

 

I'm pretty leery about permanently assigning such formats as I might accidently forget that is a formatted value if I don't use the data set for awhile and wonder why it doesn't match the collection documents.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 853 views
  • 0 likes
  • 3 in conversation