DATA Step, Macro, Functions and more

Setting values for string variable into two categories

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Setting values for string variable into two categories

New SAS user, editing an existing (very experienced) user's program. Long story short, when I run the code below, the 'Other' category isn't being printed out, it's just being coded as Frequency Missing. How can I get it to be a value in the frequency table?

 

Relevant coding bits: 

Proc format;

VALUE $ZIPFMT ' 48021'='InCounty'
                              OTHER='OutCounty' ;

Data Students;
       Set &student;
       Format ZipCode $zipfmt.;

Title 'T16: Zip Code';
Proc Freq data=Students order=formatted;
Tables ZipCode;
run;
Title;

 

 

Thanks in advance


Accepted Solutions
Solution
‎04-16-2018 02:11 PM
Super User
Posts: 23,724

Re: Setting values for string variable into two categories

Add missing to the FREQ statement and see if it shows up correctly.

 

Title 'T16: Zip Code';
Proc Freq data=Students order=formatted;
Tables ZipCode/missing;
run;
Title;

View solution in original post


All Replies
Solution
‎04-16-2018 02:11 PM
Super User
Posts: 23,724

Re: Setting values for string variable into two categories

Add missing to the FREQ statement and see if it shows up correctly.

 

Title 'T16: Zip Code';
Proc Freq data=Students order=formatted;
Tables ZipCode/missing;
run;
Title;
Super User
Posts: 6,775

Re: Setting values for string variable into two categories

[ Edited ]

@Reeza has the right idea.  Prior to changing the code, however, you have to make a decision.  What should happen if ZipCode has a missing value?  Should it be counted in the "OutCounty" category, or should it display as missing (neither "InCounty" nor "OutCounty")?

 

The proposed solution places missing values in the "OutCounty" category.

New Contributor
Posts: 2

Re: Setting values for string variable into two categories

Posted in reply to Astounding

Thank you both so much. I've been trying to resolve this for hours. The code example provided works perfectly for me for this task, but what would I do differently if  *did* want OutCounty distinct from missing values?

 

 

 

 

Super User
Posts: 6,775

Re: Setting values for string variable into two categories

You would have to change the format definition.  It currently looks like this:

 

Proc format;

VALUE $ZIPFMT ' 48021'='InCounty'
                              OTHER='OutCounty' ;

 

You would need to add a  category:

 

Proc format;

VALUE $ZIPFMT ' 48021'='InCounty'

                              ' ' = 'Missing'
                              OTHER='OutCounty' ;

 

Make sure that OTHER= gets defined last.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 125 views
  • 5 likes
  • 3 in conversation