BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
psh23
Fluorite | Level 6

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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

5 REPLIES 5
ChrisBrooks
Ammonite | Level 13

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;
psh23
Fluorite | Level 6

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

Patrick
Opal | Level 21

@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;
ChrisBrooks
Ammonite | Level 13

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 1054 views
  • 0 likes
  • 3 in conversation