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

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!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
This often happens when you have a format applied on the data. To check what the format is and what the variable type is you can run a PROC CONTENTS. Post the output of that directly to the forum and we can help you from there.

proc contents data=yourDatasetName;
run;

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

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?

 

 

--
Paige Miller
AbuYusuf
Calcite | Level 5

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.

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
ballardw
Super User

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.

Reeza
Super User
This often happens when you have a format applied on the data. To check what the format is and what the variable type is you can run a PROC CONTENTS. Post the output of that directly to the forum and we can help you from there.

proc contents data=yourDatasetName;
run;
AbuYusuf
Calcite | Level 5

That's exactly what happened. Thank you very much!

Patrick
Opal | Level 21

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.

Capture.JPG

AbuYusuf
Calcite | Level 5

Thank you very much for your help!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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