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

I'm doing a BRFSS dataset. For a variable on Lung Cancer Screening, there are 5 outputs (1,2,3,7,9). I'm trying to combine 2,3,7,9 into a one output. So I'll have 1 and then (2,3,7,9) as two variables. What is the best way to proceed with this?

 

Thank you. 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

It should work though output order may not be as desired with "No" generally appearing before "Yes" Personally not a fan of Yes/no text coded variables. If you code numeric 1 instead of "Yes" and 0 instead of "No" then there are lots of reporting tricks such as : Sum of the variable is number of yes, mean is the percent of yes, if Range over records is zero then all present values are the same.

You could create a 1/0 numeric as :

Newvar = (LCSCTSCN='1' );

SAS will by default return 1 for a logical comparison when true and 0 for false.  If you really want to see yes and no then an appropriate format would be in order. Allowing you to have both worlds, the categorical yes/no as needed and numeric for those time it is nicer.

 

In SurveyMeans you would be able to use the variable as a Domain variable but not a Var variable.(Can't add, average or find a variance for a text value)

The format I supplied previously would require a $ in front of the format name,you could use "Yes" or "No" for formatted values.

 

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Can you provide some sample data and what your desired result looks like? Help us help you 🙂

ballardw
Super User

Typically the 7 and 9 for responses would be either Don't Know or Refused in BRFSS data. Are you sure you want those codes in the analysis?

 

For minimum work on your data set you might try just creating a custom format and then when you need the two levels use that format.

proc format library=work;
value twolevel
1 = '1'
2,3,7,9 = '2,3,7 or 9'
;
run;

data example;
	input x;
datalines;
1 
2
3
7
9
;

proc print data=example;
	format x twolevel.;
run;

Proc freq data=example;
   tables x;
	format x twolevel.;
run;

The groups created by formats are used for almost all analysis, reporting and graphing procedures in SAS.

One of the advantages of the format approach is that you could have another format that groups the 2 and 3 together and the 7 and 9 if some ones to see the Don't  Know/ Refused separated out.

 

The question also comes up as what are you doing with the data? Most serious analysis will start with the Survey procs such as SurveyFreq, SurveyMeans, SurveyLogistic or SurveyReg because the data comes from a complex sample and the weights will not be applied properly in most procedures because the sample information can't be supplied to the proc.

 

joelee1
Fluorite | Level 6

@ballardw Yeah, I want to include response 7 and 9 in my analyses. 

 

I'm currently trying 

Data work.LNGSCNELGBLE1;

set work.LNGSCNELGBLE;

If LCSCTSCN='1' then LCSTSCN='Yes;

If LCSCTSCN='2,3,7,9' then LCSTSCN='No';

Run;

 

I am using Proc SurveyFreq, Means and Logistic in my analyses. I've setup those analyses, but then decided that I want to combine the original response variables. Does my above code seem like a logical way to combine them? And then after do all my Proc analyses?

 

Thank you both for your help. 

ballardw
Super User

It should work though output order may not be as desired with "No" generally appearing before "Yes" Personally not a fan of Yes/no text coded variables. If you code numeric 1 instead of "Yes" and 0 instead of "No" then there are lots of reporting tricks such as : Sum of the variable is number of yes, mean is the percent of yes, if Range over records is zero then all present values are the same.

You could create a 1/0 numeric as :

Newvar = (LCSCTSCN='1' );

SAS will by default return 1 for a logical comparison when true and 0 for false.  If you really want to see yes and no then an appropriate format would be in order. Allowing you to have both worlds, the categorical yes/no as needed and numeric for those time it is nicer.

 

In SurveyMeans you would be able to use the variable as a Domain variable but not a Var variable.(Can't add, average or find a variance for a text value)

The format I supplied previously would require a $ in front of the format name,you could use "Yes" or "No" for formatted values.

 

joelee1
Fluorite | Level 6
Thank you. Yeah, I'm changing it to numerical as you are right, many of those functions will work better. Thanks for the great, detailed advice and quick responses

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 583 views
  • 1 like
  • 3 in conversation