Hello,
I have one formatted variable (interaction_type2) and I can't figure out how to get SAS to recognize the formatted terms to create new variables or to subset? This code returns missing values for both new variables, because SAS is looking for the unformatted value. Can someone explain this to me? Thanks!
Proc format;
Value $interaction
'01'='Ambulatory patient services'
'02'='Day surgery patient'
'03'='Emergency patient'
'04'='Home visits'
'05'='Hospice'
'06'='Imaging'
'07'='Inpatient'
'08'='Inpatient psych'
'09'='Inpatient rehab'
'10'='Labs and diagnostics.nonimaging'
'11'='Letter / Email'
'12'='Not recorded'
'13'='Nursing home / Assisted living'
'14'='Observation patient'
'15'='Office or clinic patient'
'16'='Other orders'
'17'='Other patient type'
'18'='Other physician advice'
'19'='Palliative care'
'20'='Prescriptions and refills'
'21'='Skilled nursing facility inpatient'
'22'='Swing bed'
'23'='Unknown patient type'
'24'='Urgent care'
'25'='Long term acute care'
'26'='Other Reports / Results'
'27'='Telephone / Online';
Value $providerrole
'01'='ADMITTING'
'02'='ATTENDING'
'03'='BILLING'
'04'='CONSULTING'
'05'='DISCHARGING'
'06'='ORDERING'
'07'='OTHER'
'08'='PERFORMING'
'09'='REFERRING'
'10'='SCHEDULING';
format interaction_type2 $interaction. provider_role2 $providerrole.;
run;
data encounter; set m.provider_2007_to_2017_tr;
if specialty in ("Family Medicine" "Internal Medicine" "Primary Care" "Cardiology" "Emergency Medicine") ;
if interaction_type2 in (
'Office or clinic patient'
) then outpt = 1;
else if interaction_type2 in (
'Ambulatory patient services'
'Day surgery patient'
'Emergency patient'
'Inpatient'
'Inpatient psych'
'Inpatient rehab'
'Observation patient'
'Skilled nursing facility inpatient'
'Swing bed'
) then inpt = 1;
/*format interaction_type2 $interaction. provider_role2 $providerrole.; */
run;
You would normally use the codes and not the labels in selections and then just have an inline comment what you're selecting.
If you want to use the labels then you need to write these labels first as done below:
if put(interaction_type2,$interaction.) in ( 'Office or clinic patient' ) then
outpt = 1;
You need to have the FORMAT statement actually in the data step - I'm a little surprised your Proc Format doesn't error to be honest - here's a simple example
data test;
format interaction_type2 $interaction. provider_role2 $providerrole.;
interaction_type2='01';
provider_role2='02';
run;
I do have a format in the data step, it is commented out at the end of the code
You would normally use the codes and not the labels in selections and then just have an inline comment what you're selecting.
If you want to use the labels then you need to write these labels first as done below:
if put(interaction_type2,$interaction.) in ( 'Office or clinic patient' ) then
outpt = 1;
Thank you!
My point exactly - SAS isn't going to use it if it's commented out......
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.