remove a variable while formatting

Reply
Occasional Contributor GS2
Occasional Contributor
Posts: 16

remove a variable while formatting

Hi,

 

I am writing a format statement and have 'N/A' as a variable that I would like exclude from the crosstabs I am running. Is their a way to write that into my format statement? Thanks

Super User
Posts: 10,239

Re: remove a variable while formatting

The format statement just assigns formats.

To exclude variables, either don't include them in statements (eg that define tables in tabulate or freq), or drop them from datasets using the drop statement or dataset option.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 10,239

Re: remove a variable while formatting

PS for detailed help, post your code (see https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor GS2
Occasional Contributor
Posts: 16

Re: remove a variable while formatting

Posted in reply to KurtBremser

value $Used_a_recommendation 'Yes' = 'Yes'

'No' = 'No'

'N/A' = 'N/A';

 

This is my code and I want to remove the N/A so that when I crosstabs it does not show up

Super User
Posts: 10,239

Re: remove a variable while formatting

So we're not talking about removing a variable, but removing a value!

 

If you want to exclude certain values, keep them out of the input to the procedure by using a where= dataset option on the input dataset.

 

Your format does not make sense at all, as it just replaces values with identical values. What were you trying to accomplish with it?

 

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor GS2
Occasional Contributor
Posts: 16

Re: remove a variable while formatting

Posted in reply to KurtBremser

It is part of my larger format statement. I was formatting and running a crosstabs from the format, so I needed that variable in the format to crosstabs against even though I did not want to change any of the values.

 

I am just trying to create a chart based of the formatted variables and remove the 'N/A' as it is not needed for my graph.

Your solution would be on my import statement to write a where statement that excludes all the 'N/A's of that specific variable?

 

Do you have an example of what that would look like? Thanks

Super User
Posts: 10,239

Re: remove a variable while formatting

Please post your code of the tabulation/chart procedure.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor GS2
Occasional Contributor
Posts: 16

Re: remove a variable while formatting

Posted in reply to KurtBremser

proc freq data = mylib.a;

tables Used_a_recommendation*Race /list missing;

format Used_a_recommendation $Used_a_recommendation. Race $Race.;

title Table 8. Used a Recommendation crosstabs by Race;

run;

Super User
Posts: 10,239

Re: remove a variable while formatting

proc freq data = mylib.a (where=(Used_a_recommendation ne 'N/A'));
tables Used_a_recommendation*Race /list missing;
format Used_a_recommendation $Used_a_recommendation. Race $Race.;
title Table 8. Used a Recommendation crosstabs by Race;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor GS2
Occasional Contributor
Posts: 16

Re: remove a variable while formatting

Posted in reply to KurtBremser

That worked perfectly. Thank you!

Super User
Posts: 10,239

Re: remove a variable while formatting

If

  • you had posted the code in your initial post
  • stated that you did not want the value 'N/A' of variable Used_a_recommendation in your frequeny table

I could have given you the solution in the first answer. See Maxim 42.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 10 replies
  • 120 views
  • 0 likes
  • 2 in conversation