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.
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.
Can you provide some sample data and what your desired result looks like? Help us help you 🙂
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.
@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.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.