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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 2 replies
  • 570 views
  • 0 likes
  • 3 in conversation