Hi,
I am working with survey data, and my question of interest has 3 possible values: yes, no, and missing. I used proc tabulate to create a data set that contains row percent by certain characteristics. When I open the data, the question I am analyzing is a numeric variable, but when I look at the values, they are yes, no, and missing. I would like to map this data, but only the "no" responses. The problem is that I can't figure out a way how to work with this data. It doesn't let me put double quotes around yes, no, and missing, and it doesn't work without them either. I would be grateful for your help!
How do you know they are numeric? What do you look at that tells you they are numeric?
If you run PROC CONTENTS, is the variable shown as numeric? Is the variable formatted?
Thank you for your response. When I open the data set, the question of interest (P005) is represented by a circle with 123 inside. I attached a Word document with a screenshot.
@AbuYusuf wrote:
Thank you for your response. When I open the data set, the question of interest (P005) is represented by a circle with 123 inside. I attached a Word document with a screenshot.
Many of us will not open Microsoft Office documents as they can be a security threat.
Show us the screenshot by including it in your reply.
Please run PROC CONTENTS on this data and show us the relevant parts of the PROC CONTENTS output.
Example input data
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
And the Proc Tabulate code you are using.
I haven't seen Proc Tabulate change a variable type in an output data set.
Or run Proc Contents on your input data set and share that. I strongly suspect that you have a FORMAT permanently associated with the variable that displays those values.
That's exactly what happened. Thank you very much!
SAS allows you to assign formats to variables. In doing so SAS will print values formatted and not in their raw form. That's what's happening here.
To subset your data you need to either use the internal value or you need to use the format explicitly in the where clause/if condition.
Using Proc Contents allows you to list the metadata of your table and it will show you which format has been applied to which variable.
For your P005 variable subsetting would need to look along the line of below.
Using formatted value: if put(p005,<format name>) = 'Yes'
Using internal value: if p005=1;
Another way to get what you need:
Using the Filter & Sort or Query Builder you can have EG pull out the values. Just click through the wizard and then inspect the code generated. This will show you what you need to do if coding yourself.
Thank you very much for your help!
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.