DATA Step, Macro, Functions and more

sas not recognizing formatted values when creating new variable

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

sas not recognizing formatted values when creating new variable

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;

 


Accepted Solutions
Solution
‎10-27-2017 04:47 AM
Respected Advisor
Posts: 4,668

Re: sas not recognizing formatted values when creating new variable

@psh23

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;

View solution in original post


All Replies
Valued Guide
Posts: 570

Re: sas not recognizing formatted values when creating new variable

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;
Contributor
Posts: 25

Re: sas not recognizing formatted values when creating new variable

Posted in reply to ChrisBrooks

I do have a format in the data step, it is commented out at the end of the code

Solution
‎10-27-2017 04:47 AM
Respected Advisor
Posts: 4,668

Re: sas not recognizing formatted values when creating new variable

@psh23

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;
Contributor
Posts: 25

Re: sas not recognizing formatted values when creating new variable

Thank you!

Valued Guide
Posts: 570

Re: sas not recognizing formatted values when creating new variable

My point exactly - SAS isn't going to use it if it's commented out......

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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