BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have data which contains list of people with their sex, age and the country they moved from and the state they moved to:

NAME AGE SEX FROM TO
John Smith 25 M Canada Maryland
Mary Fernandez 4 F Spain Illinois
etc.

I need 2 datasets (one for males and one for females) for each US state:

In these datasets there should be numbers of people moving to the particular state totalled per foreign country by sex and age.

For example I should be able to look at the Maryland (male) table and see that 12 men aged 36 moved there from Canada for example.

Anyone have any idea how I can do this or even get started? I am not a programmer and I am stuck. Thanks!

mu Message was edited by: michaelaunsworth
4 REPLIES 4
Doc_Duke
Rhodochrosite | Level 12
Use PROC FREQ and output the table to a dataset, then split the dataset (or run FREQ twice, once for men and once for women; men shown below):

PROC FREQ DATA=mydata(WHERE=(sex='M'));
TABLES to*from*age/out=males;
RUN;
deleted_user
Not applicable
Thanks Doc, the HTML output is exactly what I was looking for

Other than cutting and pasting, is there any way of getting the tables in the HTML output into either a SAS dataset or an excel dataset?
ssas
Calcite | Level 5
Hi,
in my view first prepare the dataset first ( sdata).
later

data maledataset femaledataset;
set sdata;
if gender eq "F" then output femaledataset;
else if gender eq "M" then output maledataset;
run;

/* it would create one for male and another for female.*/

hope it may help you
Doc_Duke
Rhodochrosite | Level 12
One approach to getting the output into a dataset or export is to use ODS. You can create/output/manipulate pretty much anything you can print from a procedure. You'll need to read a good bit of documentation or BBUs to become proficient, but the results can be quite useful.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1190 views
  • 0 likes
  • 3 in conversation