BookmarkSubscribeRSS Feed
Sas_noob25
Obsidian | Level 7

Hello, 

 

I need some help summarizing a relatively small dataset by the state code that is in the data. I have locations both inside and outside of the U.S. and I'd like to summarize this so that I can see how many records are in the U.S. and how many are in different countries. 

 

Sample:

 

IDSTATE
1CA
2FC
3 
4GB
5AB
6FL 
7AB

 

I'd like to have something output that shows the state and the frequency, but ONLY if the frequency is over 25. 

 

Then I'd like to have it grouped by in U.S. vs. Outside of U.S. Is there a way to do this without individually calling out every state/territory in a data step?

 

 

2 REPLIES 2
Reeza
Super User

PROC FREQ with FORMAT.
Create a user format that maps each state to US and everything else to a different code. Then when you do the PROC FREQ you can apply that format and have it displayed as desired.

https://github.com/statgeek/SAS-Tutorials/blob/master/proc_format_example.sas

 

EDIT: If you're having trouble creating the look up table, SASHELP/SASMAPS or MAPSGSFK may have the data you need and you can create a format from one of those data sets.

Shmuel
Garnet | Level 18

Create a format to define which states are internal and which external:

proc format lib=work;
    value $statetyp
       'CA' = 'EX'
       'FC' = 'US'
       'GB' = 'EX'
      ...  /* correct mistakes */
      otherwise = 'er'  /* as error to be checked */
; run;   

then summarize using the format:

proc means data=have;
   class state;
   format state statetyp. ;
   var <list of variables to sum> ;
   output out=want sum=;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 282 views
  • 0 likes
  • 3 in conversation